File modules/editor/codemirror/test/emacs_test.min.js
Last commit: Tue May 22 22:39:54 2018 +0200 Jan Dankert Fix für PHP 7.2: 'Object' darf nun nicht mehr als Klassennamen verwendet werden. AUCH NICHT IN EINEM NAMESPACE! WTF, wozu habe ich das in einen verfickten Namespace gepackt? Wozu soll der sonst da sein??? Amateure. Daher nun notgedrungen unbenannt in 'BaseObject'.
1 (function() { 2 "use strict"; 3 4 var Pos = CodeMirror.Pos; 5 namespace = "emacs_"; 6 7 var eventCache = {}; 8 function fakeEvent(keyName) { 9 var event = eventCache[key]; 10 if (event) return event; 11 12 var ctrl, shift, alt; 13 var key = keyName.replace(/\w+-/g, function(type) { 14 if (type == "Ctrl-") ctrl = true; 15 else if (type == "Alt-") alt = true; 16 else if (type == "Shift-") shift = true; 17 return ""; 18 }); 19 var code; 20 for (var c in CodeMirror.keyNames) 21 if (CodeMirror.keyNames[c] == key) { code = c; break; } 22 if (code == null) throw new Error("Unknown key: " + key); 23 24 return eventCache[keyName] = { 25 type: "keydown", keyCode: code, ctrlKey: ctrl, shiftKey: shift, altKey: alt, 26 preventDefault: function(){}, stopPropagation: function(){} 27 }; 28 } 29 30 function sim(name, start /*, actions... */) { 31 var keys = Array.prototype.slice.call(arguments, 2); 32 testCM(name, function(cm) { 33 for (var i = 0; i < keys.length; ++i) { 34 var cur = keys[i]; 35 if (cur instanceof Pos) cm.setCursor(cur); 36 else if (cur.call) cur(cm); 37 else cm.triggerOnKeyDown(fakeEvent(cur)); 38 } 39 }, {keyMap: "emacs", value: start, mode: "javascript"}); 40 } 41 42 function at(line, ch, sticky) { return function(cm) { eqCursorPos(cm.getCursor(), Pos(line, ch, sticky)); }; } 43 function txt(str) { return function(cm) { eq(cm.getValue(), str); }; } 44 45 sim("motionHSimple", "abc", "Ctrl-F", "Ctrl-F", "Ctrl-B", at(0, 1, "after")); 46 sim("motionHMulti", "abcde", 47 "Ctrl-4", "Ctrl-F", at(0, 4, "before"), "Ctrl--", "Ctrl-2", "Ctrl-F", at(0, 2, "after"), 48 "Ctrl-5", "Ctrl-B", at(0, 0, "after")); 49 50 sim("motionHWord", "abc. def ghi", 51 "Alt-F", at(0, 3, "before"), "Alt-F", at(0, 8, "before"), 52 "Ctrl-B", "Alt-B", at(0, 5, "after"), "Alt-B", at(0, 0, "after")); 53 sim("motionHWordMulti", "abc. def ghi ", 54 "Ctrl-3", "Alt-F", at(0, 12, "before"), "Ctrl-2", "Alt-B", at(0, 5, "after"), 55 "Ctrl--", "Alt-B", at(0, 8, "before")); 56 57 sim("motionVSimple", "a\nb\nc\n", "Ctrl-N", "Ctrl-N", "Ctrl-P", at(1, 0, "after")); 58 sim("motionVMulti", "a\nb\nc\nd\ne\n", 59 "Ctrl-2", "Ctrl-N", at(2, 0, "after"), "Ctrl-F", "Ctrl--", "Ctrl-N", at(1, 1, "before"), 60 "Ctrl--", "Ctrl-3", "Ctrl-P", at(4, 1, "before")); 61 62 sim("killYank", "abc\ndef\nghi", 63 "Ctrl-F", "Ctrl-Space", "Ctrl-N", "Ctrl-N", "Ctrl-W", "Ctrl-E", "Ctrl-Y", 64 txt("ahibc\ndef\ng")); 65 sim("killRing", "abcdef", 66 "Ctrl-Space", "Ctrl-F", "Ctrl-W", "Ctrl-Space", "Ctrl-F", "Ctrl-W", 67 "Ctrl-Y", "Alt-Y", 68 txt("acdef")); 69 sim("copyYank", "abcd", 70 "Ctrl-Space", "Ctrl-E", "Alt-W", "Ctrl-Y", 71 txt("abcdabcd")); 72 73 sim("killLineSimple", "foo\nbar", "Ctrl-F", "Ctrl-K", txt("f\nbar")); 74 sim("killLineEmptyLine", "foo\n \nbar", "Ctrl-N", "Ctrl-K", txt("foo\nbar")); 75 sim("killLineMulti", "foo\nbar\nbaz", 76 "Ctrl-F", "Ctrl-F", "Ctrl-K", "Ctrl-K", "Ctrl-K", "Ctrl-A", "Ctrl-Y", 77 txt("o\nbarfo\nbaz")); 78 79 sim("moveByParagraph", "abc\ndef\n\n\nhij\nklm\n\n", 80 "Ctrl-F", "Ctrl-Down", at(2, 0), "Ctrl-Down", at(6, 0), 81 "Ctrl-N", "Ctrl-Up", at(3, 0), "Ctrl-Up", at(0, 0), 82 Pos(1, 2), "Ctrl-Down", at(2, 0), Pos(4, 2), "Ctrl-Up", at(3, 0)); 83 sim("moveByParagraphMulti", "abc\n\ndef\n\nhij\n\nklm", 84 "Ctrl-U", "2", "Ctrl-Down", at(3, 0), 85 "Shift-Alt-.", "Ctrl-3", "Ctrl-Up", at(1, 0)); 86 87 sim("moveBySentence", "sentence one! sentence\ntwo\n\nparagraph two", 88 "Alt-E", at(0, 13), "Alt-E", at(1, 3), "Ctrl-F", "Alt-A", at(0, 13)); 89 90 sim("moveByExpr", "function foo(a, b) {}", 91 "Ctrl-Alt-F", at(0, 8), "Ctrl-Alt-F", at(0, 12), "Ctrl-Alt-F", at(0, 18), 92 "Ctrl-Alt-B", at(0, 12), "Ctrl-Alt-B", at(0, 9)); 93 sim("moveByExprMulti", "foo bar baz bug", 94 "Ctrl-2", "Ctrl-Alt-F", at(0, 7), 95 "Ctrl--", "Ctrl-Alt-F", at(0, 4), 96 "Ctrl--", "Ctrl-2", "Ctrl-Alt-B", at(0, 11)); 97 sim("delExpr", "var x = [\n a,\n b\n c\n];", 98 Pos(0, 8), "Ctrl-Alt-K", txt("var x = ;"), "Ctrl-/", 99 Pos(4, 1), "Ctrl-Alt-Backspace", txt("var x = ;")); 100 sim("delExprMulti", "foo bar baz", 101 "Ctrl-2", "Ctrl-Alt-K", txt(" baz"), 102 "Ctrl-/", "Ctrl-E", "Ctrl-2", "Ctrl-Alt-Backspace", txt("foo ")); 103 104 sim("justOneSpace", "hi bye ", 105 Pos(0, 4), "Alt-Space", txt("hi bye "), 106 Pos(0, 4), "Alt-Space", txt("hi b ye "), 107 "Ctrl-A", "Alt-Space", "Ctrl-E", "Alt-Space", txt(" hi b ye ")); 108 109 sim("openLine", "foo bar", "Alt-F", "Ctrl-O", txt("foo\n bar")) 110 111 sim("transposeChar", "abcd\ne", 112 "Ctrl-F", "Ctrl-T", "Ctrl-T", txt("bcad\ne"), at(0, 3), 113 "Ctrl-F", "Ctrl-T", "Ctrl-T", "Ctrl-T", txt("bcda\ne"), at(0, 4), 114 "Ctrl-F", "Ctrl-T", txt("bcde\na"), at(1, 1)); 115 116 sim("manipWordCase", "foo BAR bAZ", 117 "Alt-C", "Alt-L", "Alt-U", txt("Foo bar BAZ"), 118 "Ctrl-A", "Alt-U", "Alt-L", "Alt-C", txt("FOO bar Baz")); 119 sim("manipWordCaseMulti", "foo Bar bAz", 120 "Ctrl-2", "Alt-U", txt("FOO BAR bAz"), 121 "Ctrl-A", "Ctrl-3", "Alt-C", txt("Foo Bar Baz")); 122 123 sim("upExpr", "foo {\n bar[];\n baz(blah);\n}", 124 Pos(2, 7), "Ctrl-Alt-U", at(2, 5), "Ctrl-Alt-U", at(0, 4)); 125 sim("transposeExpr", "do foo[bar] dah", 126 Pos(0, 6), "Ctrl-Alt-T", txt("do [bar]foo dah")); 127 128 sim("clearMark", "abcde", Pos(0, 2), "Ctrl-Space", "Ctrl-F", "Ctrl-F", 129 "Ctrl-G", "Ctrl-W", txt("abcde")); 130 131 sim("delRegion", "abcde", "Ctrl-Space", "Ctrl-F", "Ctrl-F", "Delete", txt("cde")); 132 sim("backspaceRegion", "abcde", "Ctrl-Space", "Ctrl-F", "Ctrl-F", "Backspace", txt("cde")); 133 134 sim("backspaceDoesntAddToRing", "foobar", "Ctrl-F", "Ctrl-F", "Ctrl-F", "Ctrl-K", "Backspace", "Backspace", "Ctrl-Y", txt("fbar")); 135 136 testCM("save", function(cm) { 137 var saved = false; 138 CodeMirror.commands.save = function(cm) { saved = cm.getValue(); }; 139 cm.triggerOnKeyDown(fakeEvent("Ctrl-X")); 140 cm.triggerOnKeyDown(fakeEvent("Ctrl-S")); 141 is(saved, "hi"); 142 }, {value: "hi", keyMap: "emacs"}); 143 144 testCM("gotoInvalidLineFloat", function(cm) { 145 cm.openDialog = function(_, cb) { cb("2.2"); }; 146 cm.triggerOnKeyDown(fakeEvent("Alt-G")); 147 cm.triggerOnKeyDown(fakeEvent("G")); 148 }, {value: "1\n2\n3\n4", keyMap: "emacs"}); 149 })();
Downloadmodules/editor/codemirror/test/emacs_test.min.js
History Tue, 22 May 2018 22:39:54 +0200 Jan Dankert Fix für PHP 7.2: 'Object' darf nun nicht mehr als Klassennamen verwendet werden. AUCH NICHT IN EINEM NAMESPACE! WTF, wozu habe ich das in einen verfickten Namespace gepackt? Wozu soll der sonst da sein??? Amateure. Daher nun notgedrungen unbenannt in 'BaseObject'.