How to use getCursor method in Playwright Internal

Best JavaScript code snippet using playwright-internal

test.js

Source:test.js Github

copy

Full Screen

...81testCM("selection", function(cm) {82 cm.setSelection(Pos(0, 4), Pos(2, 2));83 is(cm.somethingSelected());84 eq(cm.getSelection(), "11\n222222\n33");85 eqPos(cm.getCursor(false), Pos(2, 2));86 eqPos(cm.getCursor(true), Pos(0, 4));87 cm.setSelection(Pos(1, 0));88 is(!cm.somethingSelected());89 eq(cm.getSelection(), "");90 eqPos(cm.getCursor(true), Pos(1, 0));91 cm.replaceSelection("abc", "around");92 eq(cm.getSelection(), "abc");93 eq(cm.getValue(), "111111\nabc222222\n333333");94 cm.replaceSelection("def", "end");95 eq(cm.getSelection(), "");96 eqPos(cm.getCursor(true), Pos(1, 3));97 cm.setCursor(Pos(2, 1));98 eqPos(cm.getCursor(true), Pos(2, 1));99 cm.setCursor(1, 2);100 eqPos(cm.getCursor(true), Pos(1, 2));101}, {value: "111111\n222222\n333333"});102103testCM("extendSelection", function(cm) {104 cm.setExtending(true);105 addDoc(cm, 10, 10);106 cm.setSelection(Pos(3, 5));107 eqPos(cm.getCursor("head"), Pos(3, 5));108 eqPos(cm.getCursor("anchor"), Pos(3, 5));109 cm.setSelection(Pos(2, 5), Pos(5, 5));110 eqPos(cm.getCursor("head"), Pos(5, 5));111 eqPos(cm.getCursor("anchor"), Pos(2, 5));112 eqPos(cm.getCursor("start"), Pos(2, 5));113 eqPos(cm.getCursor("end"), Pos(5, 5));114 cm.setSelection(Pos(5, 5), Pos(2, 5));115 eqPos(cm.getCursor("head"), Pos(2, 5));116 eqPos(cm.getCursor("anchor"), Pos(5, 5));117 eqPos(cm.getCursor("start"), Pos(2, 5));118 eqPos(cm.getCursor("end"), Pos(5, 5));119 cm.extendSelection(Pos(3, 2));120 eqPos(cm.getCursor("head"), Pos(3, 2));121 eqPos(cm.getCursor("anchor"), Pos(5, 5));122 cm.extendSelection(Pos(6, 2));123 eqPos(cm.getCursor("head"), Pos(6, 2));124 eqPos(cm.getCursor("anchor"), Pos(5, 5));125 cm.extendSelection(Pos(6, 3), Pos(6, 4));126 eqPos(cm.getCursor("head"), Pos(6, 4));127 eqPos(cm.getCursor("anchor"), Pos(5, 5));128 cm.extendSelection(Pos(0, 3), Pos(0, 4));129 eqPos(cm.getCursor("head"), Pos(0, 3));130 eqPos(cm.getCursor("anchor"), Pos(5, 5));131 cm.extendSelection(Pos(4, 5), Pos(6, 5));132 eqPos(cm.getCursor("head"), Pos(6, 5));133 eqPos(cm.getCursor("anchor"), Pos(4, 5));134 cm.setExtending(false);135 cm.extendSelection(Pos(0, 3), Pos(0, 4));136 eqPos(cm.getCursor("head"), Pos(0, 3));137 eqPos(cm.getCursor("anchor"), Pos(0, 4));138});139140testCM("lines", function(cm) {141 eq(cm.getLine(0), "111111");142 eq(cm.getLine(1), "222222");143 eq(cm.getLine(-1), null);144 cm.replaceRange("", Pos(1, 0), Pos(2, 0))145 cm.replaceRange("abc", Pos(1, 0), Pos(1));146 eq(cm.getValue(), "111111\nabc");147}, {value: "111111\n222222\n333333"});148149testCM("indent", function(cm) {150 cm.indentLine(1);151 eq(cm.getLine(1), " blah();");152 cm.setOption("indentUnit", 8);153 cm.indentLine(1);154 eq(cm.getLine(1), "\tblah();");155 cm.setOption("indentUnit", 10);156 cm.setOption("tabSize", 4);157 cm.indentLine(1);158 eq(cm.getLine(1), "\t\t blah();");159}, {value: "if (x) {\nblah();\n}", indentUnit: 3, indentWithTabs: true, tabSize: 8});160161testCM("indentByNumber", function(cm) {162 cm.indentLine(0, 2);163 eq(cm.getLine(0), " foo");164 cm.indentLine(0, -200);165 eq(cm.getLine(0), "foo");166 cm.setSelection(Pos(0, 0), Pos(1, 2));167 cm.indentSelection(3);168 eq(cm.getValue(), " foo\n bar\nbaz");169}, {value: "foo\nbar\nbaz"});170171test("core_defaults", function() {172 var defsCopy = {}, defs = CodeMirror.defaults;173 for (var opt in defs) defsCopy[opt] = defs[opt];174 defs.indentUnit = 5;175 defs.value = "uu";176 defs.indentWithTabs = true;177 defs.tabindex = 55;178 var place = document.getElementById("testground"), cm = CodeMirror(place);179 try {180 eq(cm.getOption("indentUnit"), 5);181 cm.setOption("indentUnit", 10);182 eq(defs.indentUnit, 5);183 eq(cm.getValue(), "uu");184 eq(cm.getOption("indentWithTabs"), true);185 eq(cm.getInputField().tabIndex, 55);186 }187 finally {188 for (var opt in defsCopy) defs[opt] = defsCopy[opt];189 place.removeChild(cm.getWrapperElement());190 }191});192193testCM("lineInfo", function(cm) {194 eq(cm.lineInfo(-1), null);195 var mark = document.createElement("span");196 var lh = cm.setGutterMarker(1, "FOO", mark);197 var info = cm.lineInfo(1);198 eq(info.text, "222222");199 eq(info.gutterMarkers.FOO, mark);200 eq(info.line, 1);201 eq(cm.lineInfo(2).gutterMarkers, null);202 cm.setGutterMarker(lh, "FOO", null);203 eq(cm.lineInfo(1).gutterMarkers, null);204 cm.setGutterMarker(1, "FOO", mark);205 cm.setGutterMarker(0, "FOO", mark);206 cm.clearGutter("FOO");207 eq(cm.lineInfo(0).gutterMarkers, null);208 eq(cm.lineInfo(1).gutterMarkers, null);209}, {value: "111111\n222222\n333333"});210211testCM("coords", function(cm) {212 cm.setSize(null, 100);213 addDoc(cm, 32, 200);214 var top = cm.charCoords(Pos(0, 0));215 var bot = cm.charCoords(Pos(200, 30));216 is(top.left < bot.left);217 is(top.top < bot.top);218 is(top.top < top.bottom);219 cm.scrollTo(null, 100);220 var top2 = cm.charCoords(Pos(0, 0));221 is(top.top > top2.top);222 eq(top.left, top2.left);223});224225testCM("coordsChar", function(cm) {226 addDoc(cm, 35, 70);227 for (var i = 0; i < 2; ++i) {228 var sys = i ? "local" : "page";229 for (var ch = 0; ch <= 35; ch += 5) {230 for (var line = 0; line < 70; line += 5) {231 cm.setCursor(line, ch);232 var coords = cm.charCoords(Pos(line, ch), sys);233 var pos = cm.coordsChar({left: coords.left + 1, top: coords.top + 1}, sys);234 eqPos(pos, Pos(line, ch));235 }236 }237 }238}, {lineNumbers: true});239240testCM("posFromIndex", function(cm) {241 cm.setValue(242 "This function should\n" +243 "convert a zero based index\n" +244 "to line and ch."245 );246247 var examples = [248 { index: -1, line: 0, ch: 0 }, // <- Tests clipping249 { index: 0, line: 0, ch: 0 },250 { index: 10, line: 0, ch: 10 },251 { index: 39, line: 1, ch: 18 },252 { index: 55, line: 2, ch: 7 },253 { index: 63, line: 2, ch: 15 },254 { index: 64, line: 2, ch: 15 } // <- Tests clipping255 ];256257 for (var i = 0; i < examples.length; i++) {258 var example = examples[i];259 var pos = cm.posFromIndex(example.index);260 eq(pos.line, example.line);261 eq(pos.ch, example.ch);262 if (example.index >= 0 && example.index < 64)263 eq(cm.indexFromPos(pos), example.index);264 }265});266267testCM("undo", function(cm) {268 cm.replaceRange("def", Pos(0, 0), Pos(0));269 eq(cm.historySize().undo, 1);270 cm.undo();271 eq(cm.getValue(), "abc");272 eq(cm.historySize().undo, 0);273 eq(cm.historySize().redo, 1);274 cm.redo();275 eq(cm.getValue(), "def");276 eq(cm.historySize().undo, 1);277 eq(cm.historySize().redo, 0);278 cm.setValue("1\n\n\n2");279 cm.clearHistory();280 eq(cm.historySize().undo, 0);281 for (var i = 0; i < 20; ++i) {282 cm.replaceRange("a", Pos(0, 0));283 cm.replaceRange("b", Pos(3, 0));284 }285 eq(cm.historySize().undo, 40);286 for (var i = 0; i < 40; ++i)287 cm.undo();288 eq(cm.historySize().redo, 40);289 eq(cm.getValue(), "1\n\n\n2");290}, {value: "abc"});291292testCM("undoDepth", function(cm) {293 cm.replaceRange("d", Pos(0));294 cm.replaceRange("e", Pos(0));295 cm.replaceRange("f", Pos(0));296 cm.undo(); cm.undo(); cm.undo();297 eq(cm.getValue(), "abcd");298}, {value: "abc", undoDepth: 4});299300testCM("undoDoesntClearValue", function(cm) {301 cm.undo();302 eq(cm.getValue(), "x");303}, {value: "x"});304305testCM("undoMultiLine", function(cm) {306 cm.operation(function() {307 cm.replaceRange("x", Pos(0, 0));308 cm.replaceRange("y", Pos(1, 0));309 });310 cm.undo();311 eq(cm.getValue(), "abc\ndef\nghi");312 cm.operation(function() {313 cm.replaceRange("y", Pos(1, 0));314 cm.replaceRange("x", Pos(0, 0));315 });316 cm.undo();317 eq(cm.getValue(), "abc\ndef\nghi");318 cm.operation(function() {319 cm.replaceRange("y", Pos(2, 0));320 cm.replaceRange("x", Pos(1, 0));321 cm.replaceRange("z", Pos(2, 0));322 });323 cm.undo();324 eq(cm.getValue(), "abc\ndef\nghi", 3);325}, {value: "abc\ndef\nghi"});326327testCM("undoComposite", function(cm) {328 cm.replaceRange("y", Pos(1));329 cm.operation(function() {330 cm.replaceRange("x", Pos(0));331 cm.replaceRange("z", Pos(2));332 });333 eq(cm.getValue(), "ax\nby\ncz\n");334 cm.undo();335 eq(cm.getValue(), "a\nby\nc\n");336 cm.undo();337 eq(cm.getValue(), "a\nb\nc\n");338 cm.redo(); cm.redo();339 eq(cm.getValue(), "ax\nby\ncz\n");340}, {value: "a\nb\nc\n"});341342testCM("undoSelection", function(cm) {343 cm.setSelection(Pos(0, 2), Pos(0, 4));344 cm.replaceSelection("");345 cm.setCursor(Pos(1, 0));346 cm.undo();347 eqPos(cm.getCursor(true), Pos(0, 2));348 eqPos(cm.getCursor(false), Pos(0, 4));349 cm.setCursor(Pos(1, 0));350 cm.redo();351 eqPos(cm.getCursor(true), Pos(0, 2));352 eqPos(cm.getCursor(false), Pos(0, 2));353}, {value: "abcdefgh\n"});354355testCM("undoSelectionAsBefore", function(cm) {356 cm.replaceSelection("abc", "around");357 cm.undo();358 cm.redo();359 eq(cm.getSelection(), "abc");360});361362testCM("selectionChangeConfusesHistory", function(cm) {363 cm.replaceSelection("abc", null, "dontmerge");364 cm.operation(function() {365 cm.setCursor(Pos(0, 0));366 cm.replaceSelection("abc", null, "dontmerge");367 });368 eq(cm.historySize().undo, 2);369});370371testCM("markTextSingleLine", function(cm) {372 forEach([{a: 0, b: 1, c: "", f: 2, t: 5},373 {a: 0, b: 4, c: "", f: 0, t: 2},374 {a: 1, b: 2, c: "x", f: 3, t: 6},375 {a: 4, b: 5, c: "", f: 3, t: 5},376 {a: 4, b: 5, c: "xx", f: 3, t: 7},377 {a: 2, b: 5, c: "", f: 2, t: 3},378 {a: 2, b: 5, c: "abcd", f: 6, t: 7},379 {a: 2, b: 6, c: "x", f: null, t: null},380 {a: 3, b: 6, c: "", f: null, t: null},381 {a: 0, b: 9, c: "hallo", f: null, t: null},382 {a: 4, b: 6, c: "x", f: 3, t: 4},383 {a: 4, b: 8, c: "", f: 3, t: 4},384 {a: 6, b: 6, c: "a", f: 3, t: 6},385 {a: 8, b: 9, c: "", f: 3, t: 6}], function(test) {386 cm.setValue("1234567890");387 var r = cm.markText(Pos(0, 3), Pos(0, 6), {className: "foo"});388 cm.replaceRange(test.c, Pos(0, test.a), Pos(0, test.b));389 var f = r.find();390 eq(f && f.from.ch, test.f); eq(f && f.to.ch, test.t);391 });392});393394testCM("markTextMultiLine", function(cm) {395 function p(v) { return v && Pos(v[0], v[1]); }396 forEach([{a: [0, 0], b: [0, 5], c: "", f: [0, 0], t: [2, 5]},397 {a: [0, 0], b: [0, 5], c: "foo\n", f: [1, 0], t: [3, 5]},398 {a: [0, 1], b: [0, 10], c: "", f: [0, 1], t: [2, 5]},399 {a: [0, 5], b: [0, 6], c: "x", f: [0, 6], t: [2, 5]},400 {a: [0, 0], b: [1, 0], c: "", f: [0, 0], t: [1, 5]},401 {a: [0, 6], b: [2, 4], c: "", f: [0, 5], t: [0, 7]},402 {a: [0, 6], b: [2, 4], c: "aa", f: [0, 5], t: [0, 9]},403 {a: [1, 2], b: [1, 8], c: "", f: [0, 5], t: [2, 5]},404 {a: [0, 5], b: [2, 5], c: "xx", f: null, t: null},405 {a: [0, 0], b: [2, 10], c: "x", f: null, t: null},406 {a: [1, 5], b: [2, 5], c: "", f: [0, 5], t: [1, 5]},407 {a: [2, 0], b: [2, 3], c: "", f: [0, 5], t: [2, 2]},408 {a: [2, 5], b: [3, 0], c: "a\nb", f: [0, 5], t: [2, 5]},409 {a: [2, 3], b: [3, 0], c: "x", f: [0, 5], t: [2, 3]},410 {a: [1, 1], b: [1, 9], c: "1\n2\n3", f: [0, 5], t: [4, 5]}], function(test) {411 cm.setValue("aaaaaaaaaa\nbbbbbbbbbb\ncccccccccc\ndddddddd\n");412 var r = cm.markText(Pos(0, 5), Pos(2, 5),413 {className: "CodeMirror-matchingbracket"});414 cm.replaceRange(test.c, p(test.a), p(test.b));415 var f = r.find();416 eqPos(f && f.from, p(test.f)); eqPos(f && f.to, p(test.t));417 });418});419420testCM("markTextUndo", function(cm) {421 var marker1, marker2, bookmark;422 marker1 = cm.markText(Pos(0, 1), Pos(0, 3),423 {className: "CodeMirror-matchingbracket"});424 marker2 = cm.markText(Pos(0, 0), Pos(2, 1),425 {className: "CodeMirror-matchingbracket"});426 bookmark = cm.setBookmark(Pos(1, 5));427 cm.operation(function(){428 cm.replaceRange("foo", Pos(0, 2));429 cm.replaceRange("bar\nbaz\nbug\n", Pos(2, 0), Pos(3, 0));430 });431 var v1 = cm.getValue();432 cm.setValue("");433 eq(marker1.find(), null); eq(marker2.find(), null); eq(bookmark.find(), null);434 cm.undo();435 eqPos(bookmark.find(), Pos(1, 5), "still there");436 cm.undo();437 var m1Pos = marker1.find(), m2Pos = marker2.find();438 eqPos(m1Pos.from, Pos(0, 1)); eqPos(m1Pos.to, Pos(0, 3));439 eqPos(m2Pos.from, Pos(0, 0)); eqPos(m2Pos.to, Pos(2, 1));440 eqPos(bookmark.find(), Pos(1, 5));441 cm.redo(); cm.redo();442 eq(bookmark.find(), null);443 cm.undo();444 eqPos(bookmark.find(), Pos(1, 5));445 eq(cm.getValue(), v1);446}, {value: "1234\n56789\n00\n"});447448testCM("markTextStayGone", function(cm) {449 var m1 = cm.markText(Pos(0, 0), Pos(0, 1));450 cm.replaceRange("hi", Pos(0, 2));451 m1.clear();452 cm.undo();453 eq(m1.find(), null);454}, {value: "hello"});455456testCM("markTextAllowEmpty", function(cm) {457 var m1 = cm.markText(Pos(0, 1), Pos(0, 2), {clearWhenEmpty: false});458 is(m1.find());459 cm.replaceRange("x", Pos(0, 0));460 is(m1.find());461 cm.replaceRange("y", Pos(0, 2));462 is(m1.find());463 cm.replaceRange("z", Pos(0, 3), Pos(0, 4));464 is(!m1.find());465 var m2 = cm.markText(Pos(0, 1), Pos(0, 2), {clearWhenEmpty: false,466 inclusiveLeft: true,467 inclusiveRight: true});468 cm.replaceRange("q", Pos(0, 1), Pos(0, 2));469 is(m2.find());470 cm.replaceRange("", Pos(0, 0), Pos(0, 3));471 is(!m2.find());472 var m3 = cm.markText(Pos(0, 1), Pos(0, 1), {clearWhenEmpty: false});473 cm.replaceRange("a", Pos(0, 3));474 is(m3.find());475 cm.replaceRange("b", Pos(0, 1));476 is(!m3.find());477}, {value: "abcde"});478479testCM("markTextStacked", function(cm) {480 var m1 = cm.markText(Pos(0, 0), Pos(0, 0), {clearWhenEmpty: false});481 var m2 = cm.markText(Pos(0, 0), Pos(0, 0), {clearWhenEmpty: false});482 cm.replaceRange("B", Pos(0, 1));483 is(m1.find() && m2.find());484}, {value: "A"});485486testCM("undoPreservesNewMarks", function(cm) {487 cm.markText(Pos(0, 3), Pos(0, 4));488 cm.markText(Pos(1, 1), Pos(1, 3));489 cm.replaceRange("", Pos(0, 3), Pos(3, 1));490 var mBefore = cm.markText(Pos(0, 0), Pos(0, 1));491 var mAfter = cm.markText(Pos(0, 5), Pos(0, 6));492 var mAround = cm.markText(Pos(0, 2), Pos(0, 4));493 cm.undo();494 eqPos(mBefore.find().from, Pos(0, 0));495 eqPos(mBefore.find().to, Pos(0, 1));496 eqPos(mAfter.find().from, Pos(3, 3));497 eqPos(mAfter.find().to, Pos(3, 4));498 eqPos(mAround.find().from, Pos(0, 2));499 eqPos(mAround.find().to, Pos(3, 2));500 var found = cm.findMarksAt(Pos(2, 2));501 eq(found.length, 1);502 eq(found[0], mAround);503}, {value: "aaaa\nbbbb\ncccc\ndddd"});504505testCM("markClearBetween", function(cm) {506 cm.setValue("aaa\nbbb\nccc\nddd\n");507 cm.markText(Pos(0, 0), Pos(2));508 cm.replaceRange("aaa\nbbb\nccc", Pos(0, 0), Pos(2));509 eq(cm.findMarksAt(Pos(1, 1)).length, 0);510});511512testCM("deleteSpanCollapsedInclusiveLeft", function(cm) {513 var from = Pos(1, 0), to = Pos(1, 1);514 var m = cm.markText(from, to, {collapsed: true, inclusiveLeft: true});515 // Delete collapsed span.516 cm.replaceRange("", from, to);517}, {value: "abc\nX\ndef"});518519testCM("bookmark", function(cm) {520 function p(v) { return v && Pos(v[0], v[1]); }521 forEach([{a: [1, 0], b: [1, 1], c: "", d: [1, 4]},522 {a: [1, 1], b: [1, 1], c: "xx", d: [1, 7]},523 {a: [1, 4], b: [1, 5], c: "ab", d: [1, 6]},524 {a: [1, 4], b: [1, 6], c: "", d: null},525 {a: [1, 5], b: [1, 6], c: "abc", d: [1, 5]},526 {a: [1, 6], b: [1, 8], c: "", d: [1, 5]},527 {a: [1, 4], b: [1, 4], c: "\n\n", d: [3, 1]},528 {bm: [1, 9], a: [1, 1], b: [1, 1], c: "\n", d: [2, 8]}], function(test) {529 cm.setValue("1234567890\n1234567890\n1234567890");530 var b = cm.setBookmark(p(test.bm) || Pos(1, 5));531 cm.replaceRange(test.c, p(test.a), p(test.b));532 eqPos(b.find(), p(test.d));533 });534});535536testCM("bookmarkInsertLeft", function(cm) {537 var br = cm.setBookmark(Pos(0, 2), {insertLeft: false});538 var bl = cm.setBookmark(Pos(0, 2), {insertLeft: true});539 cm.setCursor(Pos(0, 2));540 cm.replaceSelection("hi");541 eqPos(br.find(), Pos(0, 2));542 eqPos(bl.find(), Pos(0, 4));543 cm.replaceRange("", Pos(0, 4), Pos(0, 5));544 cm.replaceRange("", Pos(0, 2), Pos(0, 4));545 cm.replaceRange("", Pos(0, 1), Pos(0, 2));546 // Verify that deleting next to bookmarks doesn't kill them547 eqPos(br.find(), Pos(0, 1));548 eqPos(bl.find(), Pos(0, 1));549}, {value: "abcdef"});550551testCM("bookmarkCursor", function(cm) {552 var pos01 = cm.cursorCoords(Pos(0, 1)), pos11 = cm.cursorCoords(Pos(1, 1)),553 pos20 = cm.cursorCoords(Pos(2, 0)), pos30 = cm.cursorCoords(Pos(3, 0)),554 pos41 = cm.cursorCoords(Pos(4, 1));555 cm.setBookmark(Pos(0, 1), {widget: document.createTextNode("←"), insertLeft: true});556 cm.setBookmark(Pos(2, 0), {widget: document.createTextNode("←"), insertLeft: true});557 cm.setBookmark(Pos(1, 1), {widget: document.createTextNode("→")});558 cm.setBookmark(Pos(3, 0), {widget: document.createTextNode("→")});559 var new01 = cm.cursorCoords(Pos(0, 1)), new11 = cm.cursorCoords(Pos(1, 1)),560 new20 = cm.cursorCoords(Pos(2, 0)), new30 = cm.cursorCoords(Pos(3, 0));561 near(new01.left, pos01.left, 1);562 near(new01.top, pos01.top, 1);563 is(new11.left > pos11.left, "at right, middle of line");564 near(new11.top == pos11.top, 1);565 near(new20.left, pos20.left, 1);566 near(new20.top, pos20.top, 1);567 is(new30.left > pos30.left, "at right, empty line");568 near(new30.top, pos30, 1);569 cm.setBookmark(Pos(4, 0), {widget: document.createTextNode("→")});570 is(cm.cursorCoords(Pos(4, 1)).left > pos41.left, "single-char bug");571}, {value: "foo\nbar\n\n\nx\ny"});572573testCM("multiBookmarkCursor", function(cm) {574 if (phantom) return;575 var ms = [], m;576 function add(insertLeft) {577 for (var i = 0; i < 3; ++i) {578 var node = document.createElement("span");579 node.innerHTML = "X";580 ms.push(cm.setBookmark(Pos(0, 1), {widget: node, insertLeft: insertLeft}));581 }582 }583 var base1 = cm.cursorCoords(Pos(0, 1)).left, base4 = cm.cursorCoords(Pos(0, 4)).left;584 add(true);585 near(base1, cm.cursorCoords(Pos(0, 1)).left, 1);586 while (m = ms.pop()) m.clear();587 add(false);588 near(base4, cm.cursorCoords(Pos(0, 1)).left, 1);589}, {value: "abcdefg"});590591testCM("getAllMarks", function(cm) {592 addDoc(cm, 10, 10);593 var m1 = cm.setBookmark(Pos(0, 2));594 var m2 = cm.markText(Pos(0, 2), Pos(3, 2));595 var m3 = cm.markText(Pos(1, 2), Pos(1, 8));596 var m4 = cm.markText(Pos(8, 0), Pos(9, 0));597 eq(cm.getAllMarks().length, 4);598 m1.clear();599 m3.clear();600 eq(cm.getAllMarks().length, 2);601});602603testCM("bug577", function(cm) {604 cm.setValue("a\nb");605 cm.clearHistory();606 cm.setValue("fooooo");607 cm.undo();608});609610testCM("scrollSnap", function(cm) {611 cm.setSize(100, 100);612 addDoc(cm, 200, 200);613 cm.setCursor(Pos(100, 180));614 var info = cm.getScrollInfo();615 is(info.left > 0 && info.top > 0);616 cm.setCursor(Pos(0, 0));617 info = cm.getScrollInfo();618 is(info.left == 0 && info.top == 0, "scrolled clean to top");619 cm.setCursor(Pos(100, 180));620 cm.setCursor(Pos(199, 0));621 info = cm.getScrollInfo();622 is(info.left == 0 && info.top + 2 > info.height - cm.getScrollerElement().clientHeight, "scrolled clean to bottom");623});624625testCM("scrollIntoView", function(cm) {626 if (phantom) return;627 var outer = cm.getWrapperElement().getBoundingClientRect();628 function test(line, ch, msg) {629 var pos = Pos(line, ch);630 cm.scrollIntoView(pos);631 var box = cm.charCoords(pos, "window");632 is(box.left >= outer.left, msg + " (left)");633 is(box.right <= outer.right, msg + " (right)");634 is(box.top >= outer.top, msg + " (top)");635 is(box.bottom <= outer.bottom, msg + " (bottom)");636 }637 addDoc(cm, 200, 200);638 test(199, 199, "bottom right");639 test(0, 0, "top left");640 test(100, 100, "center");641 test(199, 0, "bottom left");642 test(0, 199, "top right");643 test(100, 100, "center again");644});645646testCM("scrollBackAndForth", function(cm) {647 addDoc(cm, 1, 200);648 cm.operation(function() {649 cm.scrollIntoView(Pos(199, 0));650 cm.scrollIntoView(Pos(4, 0));651 });652 is(cm.getScrollInfo().top > 0);653});654655testCM("selectAllNoScroll", function(cm) {656 addDoc(cm, 1, 200);657 cm.execCommand("selectAll");658 eq(cm.getScrollInfo().top, 0);659 cm.setCursor(199);660 cm.execCommand("selectAll");661 is(cm.getScrollInfo().top > 0);662});663664testCM("selectionPos", function(cm) {665 if (phantom) return;666 cm.setSize(100, 100);667 addDoc(cm, 200, 100);668 cm.setSelection(Pos(1, 100), Pos(98, 100));669 var lineWidth = cm.charCoords(Pos(0, 200), "local").left;670 var lineHeight = (cm.charCoords(Pos(99)).top - cm.charCoords(Pos(0)).top) / 100;671 cm.scrollTo(0, 0);672 var selElt = byClassName(cm.getWrapperElement(), "CodeMirror-selected");673 var outer = cm.getWrapperElement().getBoundingClientRect();674 var sawMiddle, sawTop, sawBottom;675 for (var i = 0, e = selElt.length; i < e; ++i) {676 var box = selElt[i].getBoundingClientRect();677 var atLeft = box.left - outer.left < 30;678 var width = box.right - box.left;679 var atRight = box.right - outer.left > .8 * lineWidth;680 if (atLeft && atRight) {681 sawMiddle = true;682 is(box.bottom - box.top > 90 * lineHeight, "middle high");683 is(width > .9 * lineWidth, "middle wide");684 } else {685 is(width > .4 * lineWidth, "top/bot wide enough");686 is(width < .6 * lineWidth, "top/bot slim enough");687 if (atLeft) {688 sawBottom = true;689 is(box.top - outer.top > 96 * lineHeight, "bot below");690 } else if (atRight) {691 sawTop = true;692 is(box.top - outer.top < 2.1 * lineHeight, "top above");693 }694 }695 }696 is(sawTop && sawBottom && sawMiddle, "all parts");697}, null);698699testCM("restoreHistory", function(cm) {700 cm.setValue("abc\ndef");701 cm.replaceRange("hello", Pos(1, 0), Pos(1));702 cm.replaceRange("goop", Pos(0, 0), Pos(0));703 cm.undo();704 var storedVal = cm.getValue(), storedHist = cm.getHistory();705 if (window.JSON) storedHist = JSON.parse(JSON.stringify(storedHist));706 eq(storedVal, "abc\nhello");707 cm.setValue("");708 cm.clearHistory();709 eq(cm.historySize().undo, 0);710 cm.setValue(storedVal);711 cm.setHistory(storedHist);712 cm.redo();713 eq(cm.getValue(), "goop\nhello");714 cm.undo(); cm.undo();715 eq(cm.getValue(), "abc\ndef");716});717718testCM("doubleScrollbar", function(cm) {719 var dummy = document.body.appendChild(document.createElement("p"));720 dummy.style.cssText = "height: 50px; overflow: scroll; width: 50px";721 var scrollbarWidth = dummy.offsetWidth + 1 - dummy.clientWidth;722 document.body.removeChild(dummy);723 if (scrollbarWidth < 2) return;724 cm.setSize(null, 100);725 addDoc(cm, 1, 300);726 var wrap = cm.getWrapperElement();727 is(wrap.offsetWidth - byClassName(wrap, "CodeMirror-lines")[0].offsetWidth <= scrollbarWidth * 1.5);728});729730testCM("weirdLinebreaks", function(cm) {731 cm.setValue("foo\nbar\rbaz\r\nquux\n\rplop");732 is(cm.getValue(), "foo\nbar\nbaz\nquux\n\nplop");733 is(cm.lineCount(), 6);734 cm.setValue("\n\n");735 is(cm.lineCount(), 3);736});737738testCM("setSize", function(cm) {739 cm.setSize(100, 100);740 var wrap = cm.getWrapperElement();741 is(wrap.offsetWidth, 100);742 is(wrap.offsetHeight, 100);743 cm.setSize("100%", "3em");744 is(wrap.style.width, "100%");745 is(wrap.style.height, "3em");746 cm.setSize(null, 40);747 is(wrap.style.width, "100%");748 is(wrap.style.height, "40px");749});750751function foldLines(cm, start, end, autoClear) {752 return cm.markText(Pos(start, 0), Pos(end - 1), {753 inclusiveLeft: true,754 inclusiveRight: true,755 collapsed: true,756 clearOnEnter: autoClear757 });758}759760testCM("collapsedLines", function(cm) {761 addDoc(cm, 4, 10);762 var range = foldLines(cm, 4, 5), cleared = 0;763 CodeMirror.on(range, "clear", function() {cleared++;});764 cm.setCursor(Pos(3, 0));765 CodeMirror.commands.goLineDown(cm);766 eqPos(cm.getCursor(), Pos(5, 0));767 cm.replaceRange("abcdefg", Pos(3, 0), Pos(3));768 cm.setCursor(Pos(3, 6));769 CodeMirror.commands.goLineDown(cm);770 eqPos(cm.getCursor(), Pos(5, 4));771 cm.replaceRange("ab", Pos(3, 0), Pos(3));772 cm.setCursor(Pos(3, 2));773 CodeMirror.commands.goLineDown(cm);774 eqPos(cm.getCursor(), Pos(5, 2));775 cm.operation(function() {range.clear(); range.clear();});776 eq(cleared, 1);777});778779testCM("collapsedRangeCoordsChar", function(cm) {780 var pos_1_3 = cm.charCoords(Pos(1, 3));781 pos_1_3.left += 2; pos_1_3.top += 2;782 var opts = {collapsed: true, inclusiveLeft: true, inclusiveRight: true};783 var m1 = cm.markText(Pos(0, 0), Pos(2, 0), opts);784 eqPos(cm.coordsChar(pos_1_3), Pos(3, 3));785 m1.clear();786 var m1 = cm.markText(Pos(0, 0), Pos(1, 1), {collapsed: true, inclusiveLeft: true});787 var m2 = cm.markText(Pos(1, 1), Pos(2, 0), {collapsed: true, inclusiveRight: true});788 eqPos(cm.coordsChar(pos_1_3), Pos(3, 3));789 m1.clear(); m2.clear();790 var m1 = cm.markText(Pos(0, 0), Pos(1, 6), opts);791 eqPos(cm.coordsChar(pos_1_3), Pos(3, 3));792}, {value: "123456\nabcdef\nghijkl\nmnopqr\n"});793794testCM("collapsedRangeBetweenLinesSelected", function(cm) {795 var widget = document.createElement("span");796 widget.textContent = "\u2194";797 cm.markText(Pos(0, 3), Pos(1, 0), {replacedWith: widget});798 cm.setSelection(Pos(0, 3), Pos(1, 0));799 var selElts = byClassName(cm.getWrapperElement(), "CodeMirror-selected");800 for (var i = 0, w = 0; i < selElts.length; i++)801 w += selElts[i].offsetWidth;802 is(w > 0);803}, {value: "one\ntwo"});804805testCM("randomCollapsedRanges", function(cm) {806 addDoc(cm, 20, 500);807 cm.operation(function() {808 for (var i = 0; i < 200; i++) {809 var start = Pos(Math.floor(Math.random() * 500), Math.floor(Math.random() * 20));810 if (i % 4)811 try { cm.markText(start, Pos(start.line + 2, 1), {collapsed: true}); }812 catch(e) { if (!/overlapping/.test(String(e))) throw e; }813 else814 cm.markText(start, Pos(start.line, start.ch + 4), {"className": "foo"});815 }816 });817});818819testCM("hiddenLinesAutoUnfold", function(cm) {820 var range = foldLines(cm, 1, 3, true), cleared = 0;821 CodeMirror.on(range, "clear", function() {cleared++;});822 cm.setCursor(Pos(3, 0));823 eq(cleared, 0);824 cm.execCommand("goCharLeft");825 eq(cleared, 1);826 range = foldLines(cm, 1, 3, true);827 CodeMirror.on(range, "clear", function() {cleared++;});828 eqPos(cm.getCursor(), Pos(3, 0));829 cm.setCursor(Pos(0, 3));830 cm.execCommand("goCharRight");831 eq(cleared, 2);832}, {value: "abc\ndef\nghi\njkl"});833834testCM("hiddenLinesSelectAll", function(cm) { // Issue #484835 addDoc(cm, 4, 20);836 foldLines(cm, 0, 10);837 foldLines(cm, 11, 20);838 CodeMirror.commands.selectAll(cm);839 eqPos(cm.getCursor(true), Pos(10, 0));840 eqPos(cm.getCursor(false), Pos(10, 4));841});842843844testCM("everythingFolded", function(cm) {845 addDoc(cm, 2, 2);846 function enterPress() {847 cm.triggerOnKeyDown({type: "keydown", keyCode: 13, preventDefault: function(){}, stopPropagation: function(){}});848 }849 var fold = foldLines(cm, 0, 2);850 enterPress();851 eq(cm.getValue(), "xx\nxx");852 fold.clear();853 fold = foldLines(cm, 0, 2, true);854 eq(fold.find(), null);855 enterPress();856 eq(cm.getValue(), "\nxx\nxx");857});858859testCM("structuredFold", function(cm) {860 if (phantom) return;861 addDoc(cm, 4, 8);862 var range = cm.markText(Pos(1, 2), Pos(6, 2), {863 replacedWith: document.createTextNode("Q")864 });865 cm.setCursor(0, 3);866 CodeMirror.commands.goLineDown(cm);867 eqPos(cm.getCursor(), Pos(6, 2));868 CodeMirror.commands.goCharLeft(cm);869 eqPos(cm.getCursor(), Pos(1, 2));870 CodeMirror.commands.delCharAfter(cm);871 eq(cm.getValue(), "xxxx\nxxxx\nxxxx");872 addDoc(cm, 4, 8);873 range = cm.markText(Pos(1, 2), Pos(6, 2), {874 replacedWith: document.createTextNode("M"),875 clearOnEnter: true876 });877 var cleared = 0;878 CodeMirror.on(range, "clear", function(){++cleared;});879 cm.setCursor(0, 3);880 CodeMirror.commands.goLineDown(cm);881 eqPos(cm.getCursor(), Pos(6, 2));882 CodeMirror.commands.goCharLeft(cm);883 eqPos(cm.getCursor(), Pos(6, 1));884 eq(cleared, 1);885 range.clear();886 eq(cleared, 1);887 range = cm.markText(Pos(1, 2), Pos(6, 2), {888 replacedWith: document.createTextNode("Q"),889 clearOnEnter: true890 });891 range.clear();892 cm.setCursor(1, 2);893 CodeMirror.commands.goCharRight(cm);894 eqPos(cm.getCursor(), Pos(1, 3));895 range = cm.markText(Pos(2, 0), Pos(4, 4), {896 replacedWith: document.createTextNode("M")897 });898 cm.setCursor(1, 0);899 CodeMirror.commands.goLineDown(cm);900 eqPos(cm.getCursor(), Pos(2, 0));901}, null);902903testCM("nestedFold", function(cm) {904 addDoc(cm, 10, 3);905 function fold(ll, cl, lr, cr) {906 return cm.markText(Pos(ll, cl), Pos(lr, cr), {collapsed: true});907 }908 var inner1 = fold(0, 6, 1, 3), inner2 = fold(0, 2, 1, 8), outer = fold(0, 1, 2, 3), inner0 = fold(0, 5, 0, 6);909 cm.setCursor(0, 1);910 CodeMirror.commands.goCharRight(cm);911 eqPos(cm.getCursor(), Pos(2, 3));912 inner0.clear();913 CodeMirror.commands.goCharLeft(cm);914 eqPos(cm.getCursor(), Pos(0, 1));915 outer.clear();916 CodeMirror.commands.goCharRight(cm);917 eqPos(cm.getCursor(), Pos(0, 2));918 CodeMirror.commands.goCharRight(cm);919 eqPos(cm.getCursor(), Pos(1, 8));920 inner2.clear();921 CodeMirror.commands.goCharLeft(cm);922 eqPos(cm.getCursor(), Pos(1, 7));923 cm.setCursor(0, 5);924 CodeMirror.commands.goCharRight(cm);925 eqPos(cm.getCursor(), Pos(0, 6));926 CodeMirror.commands.goCharRight(cm);927 eqPos(cm.getCursor(), Pos(1, 3));928});929930testCM("badNestedFold", function(cm) {931 addDoc(cm, 4, 4);932 cm.markText(Pos(0, 2), Pos(3, 2), {collapsed: true});933 var caught;934 try {cm.markText(Pos(0, 1), Pos(0, 3), {collapsed: true});}935 catch(e) {caught = e;}936 is(caught instanceof Error, "no error");937 is(/overlap/i.test(caught.message), "wrong error");938});939940testCM("nestedFoldOnSide", function(cm) {941 var m1 = cm.markText(Pos(0, 1), Pos(2, 1), {collapsed: true, inclusiveRight: true});942 var m2 = cm.markText(Pos(0, 1), Pos(0, 2), {collapsed: true});943 cm.markText(Pos(0, 1), Pos(0, 2), {collapsed: true}).clear();944 try { cm.markText(Pos(0, 1), Pos(0, 2), {collapsed: true, inclusiveLeft: true}); }945 catch(e) { var caught = e; }946 is(caught && /overlap/i.test(caught.message));947 var m3 = cm.markText(Pos(2, 0), Pos(2, 1), {collapsed: true});948 var m4 = cm.markText(Pos(2, 0), Pos(2, 1), {collapse: true, inclusiveRight: true});949 m1.clear(); m4.clear();950 m1 = cm.markText(Pos(0, 1), Pos(2, 1), {collapsed: true});951 cm.markText(Pos(2, 0), Pos(2, 1), {collapsed: true}).clear();952 try { cm.markText(Pos(2, 0), Pos(2, 1), {collapsed: true, inclusiveRight: true}); }953 catch(e) { var caught = e; }954 is(caught && /overlap/i.test(caught.message));955}, {value: "ab\ncd\ef"});956957testCM("editInFold", function(cm) {958 addDoc(cm, 4, 6);959 var m = cm.markText(Pos(1, 2), Pos(3, 2), {collapsed: true});960 cm.replaceRange("", Pos(0, 0), Pos(1, 3));961 cm.replaceRange("", Pos(2, 1), Pos(3, 3));962 cm.replaceRange("a\nb\nc\nd", Pos(0, 1), Pos(1, 0));963 cm.cursorCoords(Pos(0, 0));964});965966testCM("wrappingInlineWidget", function(cm) {967 cm.setSize("11em");968 var w = document.createElement("span");969 w.style.color = "red";970 w.innerHTML = "one two three four";971 cm.markText(Pos(0, 6), Pos(0, 9), {replacedWith: w});972 var cur0 = cm.cursorCoords(Pos(0, 0)), cur1 = cm.cursorCoords(Pos(0, 10));973 is(cur0.top < cur1.top);974 is(cur0.bottom < cur1.bottom);975 var curL = cm.cursorCoords(Pos(0, 6)), curR = cm.cursorCoords(Pos(0, 9));976 eq(curL.top, cur0.top);977 eq(curL.bottom, cur0.bottom);978 eq(curR.top, cur1.top);979 eq(curR.bottom, cur1.bottom);980 cm.replaceRange("", Pos(0, 9), Pos(0));981 curR = cm.cursorCoords(Pos(0, 9));982 if (phantom) return;983 eq(curR.top, cur1.top);984 eq(curR.bottom, cur1.bottom);985}, {value: "1 2 3 xxx 4", lineWrapping: true});986987testCM("changedInlineWidget", function(cm) {988 cm.setSize("10em");989 var w = document.createElement("span");990 w.innerHTML = "x";991 var m = cm.markText(Pos(0, 4), Pos(0, 5), {replacedWith: w});992 w.innerHTML = "and now the widget is really really long all of a sudden and a scrollbar is needed";993 m.changed();994 var hScroll = byClassName(cm.getWrapperElement(), "CodeMirror-hscrollbar")[0];995 is(hScroll.scrollWidth > hScroll.clientWidth);996}, {value: "hello there"});997998testCM("changedBookmark", function(cm) {999 cm.setSize("10em");1000 var w = document.createElement("span");1001 w.innerHTML = "x";1002 var m = cm.setBookmark(Pos(0, 4), {widget: w});1003 w.innerHTML = "and now the widget is really really long all of a sudden and a scrollbar is needed";1004 m.changed();1005 var hScroll = byClassName(cm.getWrapperElement(), "CodeMirror-hscrollbar")[0];1006 is(hScroll.scrollWidth > hScroll.clientWidth);1007}, {value: "abcdefg"});10081009testCM("inlineWidget", function(cm) {1010 var w = cm.setBookmark(Pos(0, 2), {widget: document.createTextNode("uu")});1011 cm.setCursor(0, 2);1012 CodeMirror.commands.goLineDown(cm);1013 eqPos(cm.getCursor(), Pos(1, 4));1014 cm.setCursor(0, 2);1015 cm.replaceSelection("hi");1016 eqPos(w.find(), Pos(0, 2));1017 cm.setCursor(0, 1);1018 cm.replaceSelection("ay");1019 eqPos(w.find(), Pos(0, 4));1020 eq(cm.getLine(0), "uayuhiuu");1021}, {value: "uuuu\nuuuuuu"});10221023testCM("wrappingAndResizing", function(cm) {1024 cm.setSize(null, "auto");1025 cm.setOption("lineWrapping", true);1026 var wrap = cm.getWrapperElement(), h0 = wrap.offsetHeight;1027 var doc = "xxx xxx xxx xxx xxx";1028 cm.setValue(doc);1029 for (var step = 10, w = cm.charCoords(Pos(0, 18), "div").right;; w += step) {1030 cm.setSize(w);1031 if (wrap.offsetHeight <= h0 * (opera_lt10 ? 1.2 : 1.5)) {1032 if (step == 10) { w -= 10; step = 1; }1033 else break;1034 }1035 }1036 // Ensure that putting the cursor at the end of the maximally long1037 // line doesn't cause wrapping to happen.1038 cm.setCursor(Pos(0, doc.length));1039 eq(wrap.offsetHeight, h0);1040 cm.replaceSelection("x");1041 is(wrap.offsetHeight > h0, "wrapping happens");1042 // Now add a max-height and, in a document consisting of1043 // almost-wrapped lines, go over it so that a scrollbar appears.1044 cm.setValue(doc + "\n" + doc + "\n");1045 cm.getScrollerElement().style.maxHeight = "100px";1046 cm.replaceRange("\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n!\n", Pos(2, 0));1047 forEach([Pos(0, doc.length), Pos(0, doc.length - 1),1048 Pos(0, 0), Pos(1, doc.length), Pos(1, doc.length - 1)],1049 function(pos) {1050 var coords = cm.charCoords(pos);1051 eqPos(pos, cm.coordsChar({left: coords.left + 2, top: coords.top + 5}));1052 });1053}, null, ie_lt8);10541055testCM("measureEndOfLine", function(cm) {1056 cm.setSize(null, "auto");1057 var inner = byClassName(cm.getWrapperElement(), "CodeMirror-lines")[0].firstChild;1058 var lh = inner.offsetHeight;1059 for (var step = 10, w = cm.charCoords(Pos(0, 7), "div").right;; w += step) {1060 cm.setSize(w);1061 if (inner.offsetHeight < 2.5 * lh) {1062 if (step == 10) { w -= 10; step = 1; }1063 else break;1064 }1065 }1066 cm.setValue(cm.getValue() + "\n\n");1067 var endPos = cm.charCoords(Pos(0, 18), "local");1068 is(endPos.top > lh * .8, "not at top");1069 is(endPos.left > w - 20, "not at right");1070 endPos = cm.charCoords(Pos(0, 18));1071 eqPos(cm.coordsChar({left: endPos.left, top: endPos.top + 5}), Pos(0, 18));1072}, {mode: "text/html", value: "<!-- foo barrr -->", lineWrapping: true}, ie_lt8 || opera_lt10);10731074testCM("scrollVerticallyAndHorizontally", function(cm) {1075 cm.setSize(100, 100);1076 addDoc(cm, 40, 40);1077 cm.setCursor(39);1078 var wrap = cm.getWrapperElement(), bar = byClassName(wrap, "CodeMirror-vscrollbar")[0];1079 is(bar.offsetHeight < wrap.offsetHeight, "vertical scrollbar limited by horizontal one");1080 var cursorBox = byClassName(wrap, "CodeMirror-cursor")[0].getBoundingClientRect();1081 var editorBox = wrap.getBoundingClientRect();1082 is(cursorBox.bottom < editorBox.top + cm.getScrollerElement().clientHeight,1083 "bottom line visible");1084}, {lineNumbers: true});10851086testCM("moveVstuck", function(cm) {1087 var lines = byClassName(cm.getWrapperElement(), "CodeMirror-lines")[0].firstChild, h0 = lines.offsetHeight;1088 var val = "fooooooooooooooooooooooooo baaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaar\n";1089 cm.setValue(val);1090 for (var w = cm.charCoords(Pos(0, 26), "div").right * 2.8;; w += 5) {1091 cm.setSize(w);1092 if (lines.offsetHeight <= 3.5 * h0) break;1093 }1094 cm.setCursor(Pos(0, val.length - 1));1095 cm.moveV(-1, "line");1096 eqPos(cm.getCursor(), Pos(0, 26));1097}, {lineWrapping: true}, ie_lt8 || opera_lt10);10981099testCM("collapseOnMove", function(cm) {1100 cm.setSelection(Pos(0, 1), Pos(2, 4));1101 cm.execCommand("goLineUp");1102 is(!cm.somethingSelected());1103 eqPos(cm.getCursor(), Pos(0, 1));1104 cm.setSelection(Pos(0, 1), Pos(2, 4));1105 cm.execCommand("goPageDown");1106 is(!cm.somethingSelected());1107 eqPos(cm.getCursor(), Pos(2, 4));1108 cm.execCommand("goLineUp");1109 cm.execCommand("goLineUp");1110 eqPos(cm.getCursor(), Pos(0, 4));1111 cm.setSelection(Pos(0, 1), Pos(2, 4));1112 cm.execCommand("goCharLeft");1113 is(!cm.somethingSelected());1114 eqPos(cm.getCursor(), Pos(0, 1));1115}, {value: "aaaaa\nb\nccccc"});11161117testCM("clickTab", function(cm) {1118 var p0 = cm.charCoords(Pos(0, 0));1119 eqPos(cm.coordsChar({left: p0.left + 5, top: p0.top + 5}), Pos(0, 0));1120 eqPos(cm.coordsChar({left: p0.right - 5, top: p0.top + 5}), Pos(0, 1));1121}, {value: "\t\n\n", lineWrapping: true, tabSize: 8});11221123testCM("verticalScroll", function(cm) {1124 cm.setSize(100, 200);1125 cm.setValue("foo\nbar\nbaz\n");1126 var sc = cm.getScrollerElement(), baseWidth = sc.scrollWidth;1127 cm.replaceRange("aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaah", Pos(0, 0), Pos(0));1128 is(sc.scrollWidth > baseWidth, "scrollbar present");1129 cm.replaceRange("foo", Pos(0, 0), Pos(0));1130 if (!phantom) eq(sc.scrollWidth, baseWidth, "scrollbar gone");1131 cm.replaceRange("aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaah", Pos(0, 0), Pos(0));1132 cm.replaceRange("bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbh", Pos(1, 0), Pos(1));1133 is(sc.scrollWidth > baseWidth, "present again");1134 var curWidth = sc.scrollWidth;1135 cm.replaceRange("foo", Pos(0, 0), Pos(0));1136 is(sc.scrollWidth < curWidth, "scrollbar smaller");1137 is(sc.scrollWidth > baseWidth, "but still present");1138});11391140testCM("extraKeys", function(cm) {1141 var outcome;1142 function fakeKey(expected, code, props) {1143 if (typeof code == "string") code = code.charCodeAt(0);1144 var e = {type: "keydown", keyCode: code, preventDefault: function(){}, stopPropagation: function(){}};1145 if (props) for (var n in props) e[n] = props[n];1146 outcome = null;1147 cm.triggerOnKeyDown(e);1148 eq(outcome, expected);1149 }1150 CodeMirror.commands.testCommand = function() {outcome = "tc";};1151 CodeMirror.commands.goTestCommand = function() {outcome = "gtc";};1152 cm.setOption("extraKeys", {"Shift-X": function() {outcome = "sx";},1153 "X": function() {outcome = "x";},1154 "Ctrl-Alt-U": function() {outcome = "cau";},1155 "End": "testCommand",1156 "Home": "goTestCommand",1157 "Tab": false});1158 fakeKey(null, "U");1159 fakeKey("cau", "U", {ctrlKey: true, altKey: true});1160 fakeKey(null, "U", {shiftKey: true, ctrlKey: true, altKey: true});1161 fakeKey("x", "X");1162 fakeKey("sx", "X", {shiftKey: true});1163 fakeKey("tc", 35);1164 fakeKey(null, 35, {shiftKey: true});1165 fakeKey("gtc", 36);1166 fakeKey("gtc", 36, {shiftKey: true});1167 fakeKey(null, 9);1168}, null, window.opera && mac);11691170testCM("wordMovementCommands", function(cm) {1171 cm.execCommand("goWordLeft");1172 eqPos(cm.getCursor(), Pos(0, 0));1173 cm.execCommand("goWordRight"); cm.execCommand("goWordRight");1174 eqPos(cm.getCursor(), Pos(0, 7));1175 cm.execCommand("goWordLeft");1176 eqPos(cm.getCursor(), Pos(0, 5));1177 cm.execCommand("goWordRight"); cm.execCommand("goWordRight");1178 eqPos(cm.getCursor(), Pos(0, 12));1179 cm.execCommand("goWordLeft");1180 eqPos(cm.getCursor(), Pos(0, 9));1181 cm.execCommand("goWordRight"); cm.execCommand("goWordRight"); cm.execCommand("goWordRight");1182 eqPos(cm.getCursor(), Pos(0, 24));1183 cm.execCommand("goWordRight"); cm.execCommand("goWordRight");1184 eqPos(cm.getCursor(), Pos(1, 9));1185 cm.execCommand("goWordRight");1186 eqPos(cm.getCursor(), Pos(1, 13));1187 cm.execCommand("goWordRight"); cm.execCommand("goWordRight");1188 eqPos(cm.getCursor(), Pos(2, 0));1189}, {value: "this is (the) firstline.\na foo12\u00e9\u00f8\u00d7bar\n"});11901191testCM("groupMovementCommands", function(cm) {1192 cm.execCommand("goGroupLeft");1193 eqPos(cm.getCursor(), Pos(0, 0));1194 cm.execCommand("goGroupRight");1195 eqPos(cm.getCursor(), Pos(0, 4));1196 cm.execCommand("goGroupRight");1197 eqPos(cm.getCursor(), Pos(0, 7));1198 cm.execCommand("goGroupRight");1199 eqPos(cm.getCursor(), Pos(0, 10));1200 cm.execCommand("goGroupLeft");1201 eqPos(cm.getCursor(), Pos(0, 7));1202 cm.execCommand("goGroupRight"); cm.execCommand("goGroupRight"); cm.execCommand("goGroupRight");1203 eqPos(cm.getCursor(), Pos(0, 15));1204 cm.setCursor(Pos(0, 17));1205 cm.execCommand("goGroupLeft");1206 eqPos(cm.getCursor(), Pos(0, 16));1207 cm.execCommand("goGroupLeft");1208 eqPos(cm.getCursor(), Pos(0, 14));1209 cm.execCommand("goGroupRight"); cm.execCommand("goGroupRight");1210 eqPos(cm.getCursor(), Pos(0, 20));1211 cm.execCommand("goGroupRight");1212 eqPos(cm.getCursor(), Pos(1, 0));1213 cm.execCommand("goGroupRight");1214 eqPos(cm.getCursor(), Pos(1, 2));1215 cm.execCommand("goGroupRight");1216 eqPos(cm.getCursor(), Pos(1, 5));1217 cm.execCommand("goGroupLeft"); cm.execCommand("goGroupLeft");1218 eqPos(cm.getCursor(), Pos(1, 0));1219 cm.execCommand("goGroupLeft");1220 eqPos(cm.getCursor(), Pos(0, 20));1221 cm.execCommand("goGroupLeft");1222 eqPos(cm.getCursor(), Pos(0, 16));1223}, {value: "booo ba---quux. ffff\n abc d"});12241225testCM("groupsAndWhitespace", function(cm) {1226 var positions = [Pos(0, 0), Pos(0, 2), Pos(0, 5), Pos(0, 9), Pos(0, 11),1227 Pos(1, 0), Pos(1, 2), Pos(1, 5)];1228 for (var i = 1; i < positions.length; i++) {1229 cm.execCommand("goGroupRight");1230 eqPos(cm.getCursor(), positions[i]);1231 }1232 for (var i = positions.length - 2; i >= 0; i--) {1233 cm.execCommand("goGroupLeft");1234 eqPos(cm.getCursor(), i == 2 ? Pos(0, 6) : positions[i]);1235 }1236}, {value: " foo +++ \n bar"});12371238testCM("charMovementCommands", function(cm) {1239 cm.execCommand("goCharLeft"); cm.execCommand("goColumnLeft");1240 eqPos(cm.getCursor(), Pos(0, 0));1241 cm.execCommand("goCharRight"); cm.execCommand("goCharRight");1242 eqPos(cm.getCursor(), Pos(0, 2));1243 cm.setCursor(Pos(1, 0));1244 cm.execCommand("goColumnLeft");1245 eqPos(cm.getCursor(), Pos(1, 0));1246 cm.execCommand("goCharLeft");1247 eqPos(cm.getCursor(), Pos(0, 5));1248 cm.execCommand("goColumnRight");1249 eqPos(cm.getCursor(), Pos(0, 5));1250 cm.execCommand("goCharRight");1251 eqPos(cm.getCursor(), Pos(1, 0));1252 cm.execCommand("goLineEnd");1253 eqPos(cm.getCursor(), Pos(1, 5));1254 cm.execCommand("goLineStartSmart");1255 eqPos(cm.getCursor(), Pos(1, 1));1256 cm.execCommand("goLineStartSmart");1257 eqPos(cm.getCursor(), Pos(1, 0));1258 cm.setCursor(Pos(2, 0));1259 cm.execCommand("goCharRight"); cm.execCommand("goColumnRight");1260 eqPos(cm.getCursor(), Pos(2, 0));1261}, {value: "line1\n ine2\n"});12621263testCM("verticalMovementCommands", function(cm) {1264 cm.execCommand("goLineUp");1265 eqPos(cm.getCursor(), Pos(0, 0));1266 cm.execCommand("goLineDown");1267 if (!phantom) // This fails in PhantomJS, though not in a real Webkit1268 eqPos(cm.getCursor(), Pos(1, 0));1269 cm.setCursor(Pos(1, 12));1270 cm.execCommand("goLineDown");1271 eqPos(cm.getCursor(), Pos(2, 5));1272 cm.execCommand("goLineDown");1273 eqPos(cm.getCursor(), Pos(3, 0));1274 cm.execCommand("goLineUp");1275 eqPos(cm.getCursor(), Pos(2, 5));1276 cm.execCommand("goLineUp");1277 eqPos(cm.getCursor(), Pos(1, 12));1278 cm.execCommand("goPageDown");1279 eqPos(cm.getCursor(), Pos(5, 0));1280 cm.execCommand("goPageDown"); cm.execCommand("goLineDown");1281 eqPos(cm.getCursor(), Pos(5, 0));1282 cm.execCommand("goPageUp");1283 eqPos(cm.getCursor(), Pos(0, 0));1284}, {value: "line1\nlong long line2\nline3\n\nline5\n"});12851286testCM("verticalMovementCommandsWrapping", function(cm) {1287 cm.setSize(120);1288 cm.setCursor(Pos(0, 5));1289 cm.execCommand("goLineDown");1290 eq(cm.getCursor().line, 0);1291 is(cm.getCursor().ch > 5, "moved beyond wrap");1292 for (var i = 0; ; ++i) {1293 is(i < 20, "no endless loop");1294 cm.execCommand("goLineDown");1295 var cur = cm.getCursor();1296 if (cur.line == 1) eq(cur.ch, 5);1297 if (cur.line == 2) { eq(cur.ch, 1); break; }1298 }1299}, {value: "a very long line that wraps around somehow so that we can test cursor movement\nshortone\nk",1300 lineWrapping: true});13011302testCM("rtlMovement", function(cm) {1303 forEach(["خحج", "خحabcخحج", "abخحخحجcd", "abخde", "abخح2342خ1حج", "خ1ح2خح3حxج",1304 "خحcd", "1خحcd", "abcdeح1ج", "خمرحبها مها!", "foobarر", "خ ة ق",1305 "<img src=\"/בדיקה3.jpg\">"], function(line) {1306 var inv = line.charAt(0) == "خ";1307 cm.setValue(line + "\n"); cm.execCommand(inv ? "goLineEnd" : "goLineStart");1308 var cursors = byClassName(cm.getWrapperElement(), "CodeMirror-cursors")[0];1309 var cursor = cursors.firstChild;1310 var prevX = cursor.offsetLeft, prevY = cursor.offsetTop;1311 for (var i = 0; i <= line.length; ++i) {1312 cm.execCommand("goCharRight");1313 cursor = cursors.firstChild;1314 if (i == line.length) is(cursor.offsetTop > prevY, "next line");1315 else is(cursor.offsetLeft > prevX, "moved right");1316 prevX = cursor.offsetLeft; prevY = cursor.offsetTop;1317 }1318 cm.setCursor(0, 0); cm.execCommand(inv ? "goLineStart" : "goLineEnd");1319 prevX = cursors.firstChild.offsetLeft;1320 for (var i = 0; i < line.length; ++i) {1321 cm.execCommand("goCharLeft");1322 cursor = cursors.firstChild;1323 is(cursor.offsetLeft < prevX, "moved left");1324 prevX = cursor.offsetLeft;1325 }1326 });1327}, null, ie_lt9);13281329// Verify that updating a line clears its bidi ordering1330testCM("bidiUpdate", function(cm) {1331 cm.setCursor(Pos(0, 2));1332 cm.replaceSelection("خحج", "start");1333 cm.execCommand("goCharRight");1334 eqPos(cm.getCursor(), Pos(0, 4));1335}, {value: "abcd\n"});13361337testCM("movebyTextUnit", function(cm) {1338 cm.setValue("בְּרֵאשִ\nééé́\n");1339 cm.execCommand("goLineEnd");1340 for (var i = 0; i < 4; ++i) cm.execCommand("goCharRight");1341 eqPos(cm.getCursor(), Pos(0, 0));1342 cm.execCommand("goCharRight");1343 eqPos(cm.getCursor(), Pos(1, 0));1344 cm.execCommand("goCharRight");1345 cm.execCommand("goCharRight");1346 eqPos(cm.getCursor(), Pos(1, 4));1347 cm.execCommand("goCharRight");1348 eqPos(cm.getCursor(), Pos(1, 7));1349});13501351testCM("lineChangeEvents", function(cm) {1352 addDoc(cm, 3, 5);1353 var log = [], want = ["ch 0", "ch 1", "del 2", "ch 0", "ch 0", "del 1", "del 3", "del 4"];1354 for (var i = 0; i < 5; ++i) {1355 CodeMirror.on(cm.getLineHandle(i), "delete", function(i) {1356 return function() {log.push("del " + i);};1357 }(i));1358 CodeMirror.on(cm.getLineHandle(i), "change", function(i) {1359 return function() {log.push("ch " + i);};1360 }(i));1361 }1362 cm.replaceRange("x", Pos(0, 1));1363 cm.replaceRange("xy", Pos(1, 1), Pos(2));1364 cm.replaceRange("foo\nbar", Pos(0, 1));1365 cm.replaceRange("", Pos(0, 0), Pos(cm.lineCount()));1366 eq(log.length, want.length, "same length");1367 for (var i = 0; i < log.length; ++i)1368 eq(log[i], want[i]);1369});13701371testCM("scrollEntirelyToRight", function(cm) {1372 if (phantom) return;1373 addDoc(cm, 500, 2);1374 cm.setCursor(Pos(0, 500));1375 var wrap = cm.getWrapperElement(), cur = byClassName(wrap, "CodeMirror-cursor")[0];1376 is(wrap.getBoundingClientRect().right > cur.getBoundingClientRect().left);1377});13781379testCM("lineWidgets", function(cm) {1380 addDoc(cm, 500, 3);1381 var last = cm.charCoords(Pos(2, 0));1382 var node = document.createElement("div");1383 node.innerHTML = "hi";1384 var widget = cm.addLineWidget(1, node);1385 is(last.top < cm.charCoords(Pos(2, 0)).top, "took up space");1386 cm.setCursor(Pos(1, 1));1387 cm.execCommand("goLineDown");1388 eqPos(cm.getCursor(), Pos(2, 1));1389 cm.execCommand("goLineUp");1390 eqPos(cm.getCursor(), Pos(1, 1));1391});13921393testCM("lineWidgetFocus", function(cm) {1394 var place = document.getElementById("testground");1395 place.className = "offscreen";1396 try {1397 addDoc(cm, 500, 10);1398 var node = document.createElement("input");1399 var widget = cm.addLineWidget(1, node);1400 node.focus();1401 eq(document.activeElement, node);1402 cm.replaceRange("new stuff", Pos(1, 0));1403 eq(document.activeElement, node);1404 } finally {1405 place.className = "";1406 }1407});14081409testCM("lineWidgetCautiousRedraw", function(cm) {1410 var node = document.createElement("div");1411 node.innerHTML = "hahah";1412 var w = cm.addLineWidget(0, node);1413 var redrawn = false;1414 w.on("redraw", function() { redrawn = true; });1415 cm.replaceSelection("0");1416 is(!redrawn);1417}, {value: "123\n456"});141814191420var knownScrollbarWidth;1421function scrollbarWidth(measure) {1422 if (knownScrollbarWidth != null) return knownScrollbarWidth;1423 var div = document.createElement('div');1424 div.style.cssText = "width: 50px; height: 50px; overflow-x: scroll";1425 document.body.appendChild(div);1426 knownScrollbarWidth = div.offsetHeight - div.clientHeight;1427 document.body.removeChild(div);1428 return knownScrollbarWidth || 0;1429}14301431testCM("lineWidgetChanged", function(cm) {1432 addDoc(cm, 2, 300);1433 var halfScrollbarWidth = scrollbarWidth(cm.display.measure)/2;1434 cm.setOption('lineNumbers', true);1435 cm.setSize(600, cm.defaultTextHeight() * 50);1436 cm.scrollTo(null, cm.heightAtLine(125, "local"));14371438 var expectedWidgetHeight = 60;1439 var expectedLinesInWidget = 3;1440 function w() {1441 var node = document.createElement("div");1442 // we use these children with just under half width of the line to check measurements are made with correct width1443 // when placed in the measure div.1444 // If the widget is measured at a width much narrower than it is displayed at, the underHalf children will span two lines and break the test.1445 // If the widget is measured at a width much wider than it is displayed at, the overHalf children will combine and break the test.1446 // Note that this test only checks widgets where coverGutter is true, because these require extra styling to get the width right.1447 // It may also be worthwhile to check this for non-coverGutter widgets.1448 // Visually:1449 // Good:1450 // | ------------- display width ------------- |1451 // | ------- widget-width when measured ------ |1452 // | | -- under-half -- | | -- under-half -- | | 1453 // | | --- over-half --- | |1454 // | | --- over-half --- | |1455 // Height: measured as 3 lines, same as it will be when actually displayed14561457 // Bad (too narrow):1458 // | ------------- display width ------------- |1459 // | ------ widget-width when measured ----- | < -- uh oh1460 // | | -- under-half -- | |1461 // | | -- under-half -- | | < -- when measured, shoved to next line1462 // | | --- over-half --- | |1463 // | | --- over-half --- | |1464 // Height: measured as 4 lines, more than expected . Will be displayed as 3 lines!14651466 // Bad (too wide):1467 // | ------------- display width ------------- |1468 // | -------- widget-width when measured ------- | < -- uh oh1469 // | | -- under-half -- | | -- under-half -- | | 1470 // | | --- over-half --- | | --- over-half --- | | < -- when measured, combined on one line1471 // Height: measured as 2 lines, less than expected. Will be displayed as 3 lines!14721473 var barelyUnderHalfWidthHtml = '<div style="display: inline-block; height: 1px; width: '+(285 - halfScrollbarWidth)+'px;"></div>';1474 var barelyOverHalfWidthHtml = '<div style="display: inline-block; height: 1px; width: '+(305 - halfScrollbarWidth)+'px;"></div>';1475 node.innerHTML = new Array(3).join(barelyUnderHalfWidthHtml) + new Array(3).join(barelyOverHalfWidthHtml);1476 node.style.cssText = "background: yellow;font-size:0;line-height: " + (expectedWidgetHeight/expectedLinesInWidget) + "px;";1477 return node;1478 }1479 var info0 = cm.getScrollInfo();1480 var w0 = cm.addLineWidget(0, w(), { coverGutter: true });1481 var w150 = cm.addLineWidget(150, w(), { coverGutter: true });1482 var w300 = cm.addLineWidget(300, w(), { coverGutter: true });1483 var info1 = cm.getScrollInfo();1484 eq(info0.height + (3 * expectedWidgetHeight), info1.height);1485 eq(info0.top + expectedWidgetHeight, info1.top);1486 expectedWidgetHeight = 12;1487 w0.node.style.lineHeight = w150.node.style.lineHeight = w300.node.style.lineHeight = (expectedWidgetHeight/expectedLinesInWidget) + "px";1488 w0.changed(); w150.changed(); w300.changed();1489 var info2 = cm.getScrollInfo();1490 eq(info0.height + (3 * expectedWidgetHeight), info2.height);1491 eq(info0.top + expectedWidgetHeight, info2.top);1492});14931494testCM("getLineNumber", function(cm) {1495 addDoc(cm, 2, 20);1496 var h1 = cm.getLineHandle(1);1497 eq(cm.getLineNumber(h1), 1);1498 cm.replaceRange("hi\nbye\n", Pos(0, 0));1499 eq(cm.getLineNumber(h1), 3);1500 cm.setValue("");1501 eq(cm.getLineNumber(h1), null);1502});15031504testCM("jumpTheGap", function(cm) {1505 if (phantom) return;1506 var longLine = "abcdef ghiklmnop qrstuvw xyz ";1507 longLine += longLine; longLine += longLine; longLine += longLine;1508 cm.replaceRange(longLine, Pos(2, 0), Pos(2));1509 cm.setSize("200px", null);1510 cm.getWrapperElement().style.lineHeight = 2;1511 cm.refresh();1512 cm.setCursor(Pos(0, 1));1513 cm.execCommand("goLineDown");1514 eqPos(cm.getCursor(), Pos(1, 1));1515 cm.execCommand("goLineDown");1516 eqPos(cm.getCursor(), Pos(2, 1));1517 cm.execCommand("goLineDown");1518 eq(cm.getCursor().line, 2);1519 is(cm.getCursor().ch > 1);1520 cm.execCommand("goLineUp");1521 eqPos(cm.getCursor(), Pos(2, 1));1522 cm.execCommand("goLineUp");1523 eqPos(cm.getCursor(), Pos(1, 1));1524 var node = document.createElement("div");1525 node.innerHTML = "hi"; node.style.height = "30px";1526 cm.addLineWidget(0, node);1527 cm.addLineWidget(1, node.cloneNode(true), {above: true});1528 cm.setCursor(Pos(0, 2));1529 cm.execCommand("goLineDown");1530 eqPos(cm.getCursor(), Pos(1, 2));1531 cm.execCommand("goLineUp");1532 eqPos(cm.getCursor(), Pos(0, 2));1533}, {lineWrapping: true, value: "abc\ndef\nghi\njkl\n"});15341535testCM("addLineClass", function(cm) {1536 function cls(line, text, bg, wrap) {1537 var i = cm.lineInfo(line);1538 eq(i.textClass, text);1539 eq(i.bgClass, bg);1540 eq(i.wrapClass, wrap);1541 }1542 cm.addLineClass(0, "text", "foo");1543 cm.addLineClass(0, "text", "bar");1544 cm.addLineClass(1, "background", "baz");1545 cm.addLineClass(1, "wrap", "foo");1546 cls(0, "foo bar", null, null);1547 cls(1, null, "baz", "foo");1548 var lines = cm.display.lineDiv;1549 eq(byClassName(lines, "foo").length, 2);1550 eq(byClassName(lines, "bar").length, 1);1551 eq(byClassName(lines, "baz").length, 1);1552 cm.removeLineClass(0, "text", "foo");1553 cls(0, "bar", null, null);1554 cm.removeLineClass(0, "text", "foo");1555 cls(0, "bar", null, null);1556 cm.removeLineClass(0, "text", "bar");1557 cls(0, null, null, null);1558 cm.addLineClass(1, "wrap", "quux");1559 cls(1, null, "baz", "foo quux");1560 cm.removeLineClass(1, "wrap");1561 cls(1, null, "baz", null);1562}, {value: "hohoho\n"});15631564testCM("atomicMarker", function(cm) {1565 addDoc(cm, 10, 10);1566 function atom(ll, cl, lr, cr, li, ri) {1567 return cm.markText(Pos(ll, cl), Pos(lr, cr),1568 {atomic: true, inclusiveLeft: li, inclusiveRight: ri});1569 }1570 var m = atom(0, 1, 0, 5);1571 cm.setCursor(Pos(0, 1));1572 cm.execCommand("goCharRight");1573 eqPos(cm.getCursor(), Pos(0, 5));1574 cm.execCommand("goCharLeft");1575 eqPos(cm.getCursor(), Pos(0, 1));1576 m.clear();1577 m = atom(0, 0, 0, 5, true);1578 eqPos(cm.getCursor(), Pos(0, 5), "pushed out");1579 cm.execCommand("goCharLeft");1580 eqPos(cm.getCursor(), Pos(0, 5));1581 m.clear();1582 m = atom(8, 4, 9, 10, false, true);1583 cm.setCursor(Pos(9, 8));1584 eqPos(cm.getCursor(), Pos(8, 4), "set");1585 cm.execCommand("goCharRight");1586 eqPos(cm.getCursor(), Pos(8, 4), "char right");1587 cm.execCommand("goLineDown");1588 eqPos(cm.getCursor(), Pos(8, 4), "line down");1589 cm.execCommand("goCharLeft");1590 eqPos(cm.getCursor(), Pos(8, 3));1591 m.clear();1592 m = atom(1, 1, 3, 8);1593 cm.setCursor(Pos(0, 0));1594 cm.setCursor(Pos(2, 0));1595 eqPos(cm.getCursor(), Pos(3, 8));1596 cm.execCommand("goCharLeft");1597 eqPos(cm.getCursor(), Pos(1, 1));1598 cm.execCommand("goCharRight");1599 eqPos(cm.getCursor(), Pos(3, 8));1600 cm.execCommand("goLineUp");1601 eqPos(cm.getCursor(), Pos(1, 1));1602 cm.execCommand("goLineDown");1603 eqPos(cm.getCursor(), Pos(3, 8));1604 cm.execCommand("delCharBefore");1605 eq(cm.getValue().length, 80, "del chunk");1606 m = atom(3, 0, 5, 5);1607 cm.setCursor(Pos(3, 0));1608 cm.execCommand("delWordAfter");1609 eq(cm.getValue().length, 53, "del chunk");1610});16111612testCM("selectionBias", function(cm) {1613 cm.markText(Pos(0, 1), Pos(0, 3), {atomic: true});1614 cm.setCursor(Pos(0, 2));1615 eqPos(cm.getCursor(), Pos(0, 3));1616 cm.setCursor(Pos(0, 2));1617 eqPos(cm.getCursor(), Pos(0, 1));1618 cm.setCursor(Pos(0, 2), null, {bias: -1});1619 eqPos(cm.getCursor(), Pos(0, 1));1620 cm.setCursor(Pos(0, 4));1621 cm.setCursor(Pos(0, 2), null, {bias: 1});1622 eqPos(cm.getCursor(), Pos(0, 3));1623}, {value: "12345"});16241625testCM("selectionHomeEnd", function(cm) {1626 cm.markText(Pos(1, 0), Pos(1, 1), {atomic: true, inclusiveLeft: true});1627 cm.markText(Pos(1, 3), Pos(1, 4), {atomic: true, inclusiveRight: true});1628 cm.setCursor(Pos(1, 2));1629 cm.execCommand("goLineStart");1630 eqPos(cm.getCursor(), Pos(1, 1));1631 cm.execCommand("goLineEnd");1632 eqPos(cm.getCursor(), Pos(1, 3));1633}, {value: "ab\ncdef\ngh"});16341635testCM("readOnlyMarker", function(cm) {1636 function mark(ll, cl, lr, cr, at) {1637 return cm.markText(Pos(ll, cl), Pos(lr, cr),1638 {readOnly: true, atomic: at});1639 }1640 var m = mark(0, 1, 0, 4);1641 cm.setCursor(Pos(0, 2));1642 cm.replaceSelection("hi", "end");1643 eqPos(cm.getCursor(), Pos(0, 2));1644 eq(cm.getLine(0), "abcde");1645 cm.execCommand("selectAll");1646 cm.replaceSelection("oops", "around");1647 eq(cm.getValue(), "oopsbcd");1648 cm.undo();1649 eqPos(m.find().from, Pos(0, 1));1650 eqPos(m.find().to, Pos(0, 4));1651 m.clear();1652 cm.setCursor(Pos(0, 2));1653 cm.replaceSelection("hi", "around");1654 eq(cm.getLine(0), "abhicde");1655 eqPos(cm.getCursor(), Pos(0, 4));1656 m = mark(0, 2, 2, 2, true);1657 cm.setSelection(Pos(1, 1), Pos(2, 4));1658 cm.replaceSelection("t", "end");1659 eqPos(cm.getCursor(), Pos(2, 3));1660 eq(cm.getLine(2), "klto");1661 cm.execCommand("goCharLeft");1662 cm.execCommand("goCharLeft");1663 eqPos(cm.getCursor(), Pos(0, 2));1664 cm.setSelection(Pos(0, 1), Pos(0, 3));1665 cm.replaceSelection("xx", "around");1666 eqPos(cm.getCursor(), Pos(0, 3));1667 eq(cm.getLine(0), "axxhicde");1668}, {value: "abcde\nfghij\nklmno\n"});16691670testCM("dirtyBit", function(cm) {1671 eq(cm.isClean(), true);1672 cm.replaceSelection("boo", null, "test");1673 eq(cm.isClean(), false);1674 cm.undo();1675 eq(cm.isClean(), true);1676 cm.replaceSelection("boo", null, "test");1677 cm.replaceSelection("baz", null, "test");1678 cm.undo();1679 eq(cm.isClean(), false);1680 cm.markClean();1681 eq(cm.isClean(), true);1682 cm.undo();1683 eq(cm.isClean(), false);1684 cm.redo();1685 eq(cm.isClean(), true);1686});16871688testCM("changeGeneration", function(cm) {1689 cm.replaceSelection("x");1690 var softGen = cm.changeGeneration();1691 cm.replaceSelection("x");1692 cm.undo();1693 eq(cm.getValue(), "");1694 is(!cm.isClean(softGen));1695 cm.replaceSelection("x");1696 var hardGen = cm.changeGeneration(true);1697 cm.replaceSelection("x");1698 cm.undo();1699 eq(cm.getValue(), "x");1700 is(cm.isClean(hardGen));1701});17021703testCM("addKeyMap", function(cm) {1704 function sendKey(code) {1705 cm.triggerOnKeyDown({type: "keydown", keyCode: code,1706 preventDefault: function(){}, stopPropagation: function(){}});1707 }17081709 sendKey(39);1710 eqPos(cm.getCursor(), Pos(0, 1));1711 var test = 0;1712 var map1 = {Right: function() { ++test; }}, map2 = {Right: function() { test += 10; }}1713 cm.addKeyMap(map1);1714 sendKey(39);1715 eqPos(cm.getCursor(), Pos(0, 1));1716 eq(test, 1);1717 cm.addKeyMap(map2, true);1718 sendKey(39);1719 eq(test, 2);1720 cm.removeKeyMap(map1);1721 sendKey(39);1722 eq(test, 12);1723 cm.removeKeyMap(map2);1724 sendKey(39);1725 eq(test, 12);1726 eqPos(cm.getCursor(), Pos(0, 2));1727 cm.addKeyMap({Right: function() { test = 55; }, name: "mymap"});1728 sendKey(39);1729 eq(test, 55);1730 cm.removeKeyMap("mymap");1731 sendKey(39);1732 eqPos(cm.getCursor(), Pos(0, 3));1733}, {value: "abc"});17341735testCM("findPosH", function(cm) {1736 forEach([{from: Pos(0, 0), to: Pos(0, 1), by: 1},1737 {from: Pos(0, 0), to: Pos(0, 0), by: -1, hitSide: true},1738 {from: Pos(0, 0), to: Pos(0, 4), by: 1, unit: "word"},1739 {from: Pos(0, 0), to: Pos(0, 8), by: 2, unit: "word"},1740 {from: Pos(0, 0), to: Pos(2, 0), by: 20, unit: "word", hitSide: true},1741 {from: Pos(0, 7), to: Pos(0, 5), by: -1, unit: "word"},1742 {from: Pos(0, 4), to: Pos(0, 8), by: 1, unit: "word"},1743 {from: Pos(1, 0), to: Pos(1, 18), by: 3, unit: "word"},1744 {from: Pos(1, 22), to: Pos(1, 5), by: -3, unit: "word"},1745 {from: Pos(1, 15), to: Pos(1, 10), by: -5},1746 {from: Pos(1, 15), to: Pos(1, 10), by: -5, unit: "column"},1747 {from: Pos(1, 15), to: Pos(1, 0), by: -50, unit: "column", hitSide: true},1748 {from: Pos(1, 15), to: Pos(1, 24), by: 50, unit: "column", hitSide: true},1749 {from: Pos(1, 15), to: Pos(2, 0), by: 50, hitSide: true}], function(t) {1750 var r = cm.findPosH(t.from, t.by, t.unit || "char");1751 eqPos(r, t.to);1752 eq(!!r.hitSide, !!t.hitSide);1753 });1754}, {value: "line one\nline two.something.other\n"});17551756testCM("beforeChange", function(cm) {1757 cm.on("beforeChange", function(cm, change) {1758 var text = [];1759 for (var i = 0; i < change.text.length; ++i)1760 text.push(change.text[i].replace(/\s/g, "_"));1761 change.update(null, null, text);1762 });1763 cm.setValue("hello, i am a\nnew document\n");1764 eq(cm.getValue(), "hello,_i_am_a\nnew_document\n");1765 CodeMirror.on(cm.getDoc(), "beforeChange", function(doc, change) {1766 if (change.from.line == 0) change.cancel();1767 });1768 cm.setValue("oops"); // Canceled1769 eq(cm.getValue(), "hello,_i_am_a\nnew_document\n");1770 cm.replaceRange("hey hey hey", Pos(1, 0), Pos(2, 0));1771 eq(cm.getValue(), "hello,_i_am_a\nhey_hey_hey");1772}, {value: "abcdefghijk"});17731774testCM("beforeChangeUndo", function(cm) {1775 cm.replaceRange("hi", Pos(0, 0), Pos(0));1776 cm.replaceRange("bye", Pos(0, 0), Pos(0));1777 eq(cm.historySize().undo, 2);1778 cm.on("beforeChange", function(cm, change) {1779 is(!change.update);1780 change.cancel();1781 });1782 cm.undo();1783 eq(cm.historySize().undo, 0);1784 eq(cm.getValue(), "bye\ntwo");1785}, {value: "one\ntwo"});17861787testCM("beforeSelectionChange", function(cm) {1788 function notAtEnd(cm, pos) {1789 var len = cm.getLine(pos.line).length;1790 if (!len || pos.ch == len) return Pos(pos.line, pos.ch - 1);1791 return pos;1792 }1793 cm.on("beforeSelectionChange", function(cm, obj) {1794 obj.update([{anchor: notAtEnd(cm, obj.ranges[0].anchor),1795 head: notAtEnd(cm, obj.ranges[0].head)}]);1796 });17971798 addDoc(cm, 10, 10);1799 cm.execCommand("goLineEnd");1800 eqPos(cm.getCursor(), Pos(0, 9));1801 cm.execCommand("selectAll");1802 eqPos(cm.getCursor("start"), Pos(0, 0));1803 eqPos(cm.getCursor("end"), Pos(9, 9));1804});18051806testCM("change_removedText", function(cm) {1807 cm.setValue("abc\ndef");18081809 var removedText = [];1810 cm.on("change", function(cm, change) {1811 removedText.push(change.removed);1812 });18131814 cm.operation(function() {1815 cm.replaceRange("xyz", Pos(0, 0), Pos(1,1));1816 cm.replaceRange("123", Pos(0,0));1817 });18181819 eq(removedText.length, 2);1820 eq(removedText[0].join("\n"), "abc\nd");1821 eq(removedText[1].join("\n"), "");18221823 var removedText = [];1824 cm.undo();1825 eq(removedText.length, 2);1826 eq(removedText[0].join("\n"), "123");1827 eq(removedText[1].join("\n"), "xyz");18281829 var removedText = [];1830 cm.redo();1831 eq(removedText.length, 2);1832 eq(removedText[0].join("\n"), "abc\nd");1833 eq(removedText[1].join("\n"), "");1834});18351836testCM("lineStyleFromMode", function(cm) {1837 CodeMirror.defineMode("test_mode", function() {1838 return {token: function(stream) {1839 if (stream.match(/^\[[^\]]*\]/)) return " line-brackets ";1840 if (stream.match(/^\([^\)]*\)/)) return " line-background-parens ";1841 if (stream.match(/^<[^>]*>/)) return " span line-line line-background-bg ";1842 stream.match(/^\s+|^\S+/);1843 }};1844 });1845 cm.setOption("mode", "test_mode");1846 var bracketElts = byClassName(cm.getWrapperElement(), "brackets");1847 eq(bracketElts.length, 1, "brackets count");1848 eq(bracketElts[0].nodeName, "PRE");1849 is(!/brackets.*brackets/.test(bracketElts[0].className));1850 var parenElts = byClassName(cm.getWrapperElement(), "parens");1851 eq(parenElts.length, 1, "parens count");1852 eq(parenElts[0].nodeName, "DIV");1853 is(!/parens.*parens/.test(parenElts[0].className));1854 eq(parenElts[0].parentElement.nodeName, "DIV");18551856 eq(byClassName(cm.getWrapperElement(), "bg").length, 1);1857 eq(byClassName(cm.getWrapperElement(), "line").length, 1);1858 var spanElts = byClassName(cm.getWrapperElement(), "cm-span");1859 eq(spanElts.length, 2);1860 is(/^\s*cm-span\s*$/.test(spanElts[0].className));1861}, {value: "line1: [br] [br]\nline2: (par) (par)\nline3: <tag> <tag>"});18621863testCM("lineStyleFromBlankLine", function(cm) {1864 CodeMirror.defineMode("lineStyleFromBlankLine_mode", function() {1865 return {token: function(stream) { stream.skipToEnd(); return "comment"; },1866 blankLine: function() { return "line-blank"; }};1867 });1868 cm.setOption("mode", "lineStyleFromBlankLine_mode");1869 var blankElts = byClassName(cm.getWrapperElement(), "blank");1870 eq(blankElts.length, 1);1871 eq(blankElts[0].nodeName, "PRE");1872 cm.replaceRange("x", Pos(1, 0));1873 blankElts = byClassName(cm.getWrapperElement(), "blank");1874 eq(blankElts.length, 0);1875}, {value: "foo\n\nbar"});18761877CodeMirror.registerHelper("xxx", "a", "A");1878CodeMirror.registerHelper("xxx", "b", "B");1879CodeMirror.defineMode("yyy", function() {1880 return {1881 token: function(stream) { stream.skipToEnd(); },1882 xxx: ["a", "b", "q"]1883 };1884});1885CodeMirror.registerGlobalHelper("xxx", "c", function(m) { return m.enableC; }, "C");18861887testCM("helpers", function(cm) {1888 cm.setOption("mode", "yyy");1889 eq(cm.getHelpers(Pos(0, 0), "xxx").join("/"), "A/B");1890 cm.setOption("mode", {name: "yyy", modeProps: {xxx: "b", enableC: true}});1891 eq(cm.getHelpers(Pos(0, 0), "xxx").join("/"), "B/C");1892 cm.setOption("mode", "javascript");1893 eq(cm.getHelpers(Pos(0, 0), "xxx").join("/"), "");1894});18951896testCM("selectionHistory", function(cm) {1897 for (var i = 0; i < 3; i++) {1898 cm.setExtending(true);1899 cm.execCommand("goCharRight");1900 cm.setExtending(false);1901 cm.execCommand("goCharRight");1902 cm.execCommand("goCharRight");1903 }1904 cm.execCommand("undoSelection");1905 eq(cm.getSelection(), "c");1906 cm.execCommand("undoSelection");1907 eq(cm.getSelection(), "");1908 eqPos(cm.getCursor(), Pos(0, 4));1909 cm.execCommand("undoSelection");1910 eq(cm.getSelection(), "b");1911 cm.execCommand("redoSelection");1912 eq(cm.getSelection(), "");1913 eqPos(cm.getCursor(), Pos(0, 4));1914 cm.execCommand("redoSelection");1915 eq(cm.getSelection(), "c");1916 cm.execCommand("redoSelection");1917 eq(cm.getSelection(), "");1918 eqPos(cm.getCursor(), Pos(0, 6));1919}, {value: "a b c d"});19201921testCM("selectionChangeReducesRedo", function(cm) {1922 cm.replaceSelection("X");1923 cm.execCommand("goCharRight");1924 cm.undoSelection();1925 cm.execCommand("selectAll");1926 cm.undoSelection();1927 eq(cm.getValue(), "Xabc");1928 eqPos(cm.getCursor(), Pos(0, 1));1929 cm.undoSelection();1930 eq(cm.getValue(), "abc");1931}, {value: "abc"});19321933testCM("selectionHistoryNonOverlapping", function(cm) {1934 cm.setSelection(Pos(0, 0), Pos(0, 1));1935 cm.setSelection(Pos(0, 2), Pos(0, 3));1936 cm.execCommand("undoSelection");1937 eqPos(cm.getCursor("anchor"), Pos(0, 0));1938 eqPos(cm.getCursor("head"), Pos(0, 1));1939}, {value: "1234"});19401941testCM("cursorMotionSplitsHistory", function(cm) {1942 cm.replaceSelection("a");1943 cm.execCommand("goCharRight");1944 cm.replaceSelection("b");1945 cm.replaceSelection("c");1946 cm.undo();1947 eq(cm.getValue(), "a1234");1948 eqPos(cm.getCursor(), Pos(0, 2));1949 cm.undo();1950 eq(cm.getValue(), "1234");1951 eqPos(cm.getCursor(), Pos(0, 0));1952}, {value: "1234"});19531954testCM("selChangeInOperationDoesNotSplit", function(cm) {1955 for (var i = 0; i < 4; i++) {1956 cm.operation(function() {1957 cm.replaceSelection("x");1958 cm.setCursor(Pos(0, cm.getCursor().ch - 1));1959 });1960 }1961 eqPos(cm.getCursor(), Pos(0, 0));1962 eq(cm.getValue(), "xxxxa");1963 cm.undo();1964 eq(cm.getValue(), "a");1965}, {value: "a"});19661967testCM("alwaysMergeSelEventWithChangeOrigin", function(cm) {1968 cm.replaceSelection("U", null, "foo");1969 cm.setSelection(Pos(0, 0), Pos(0, 1), {origin: "foo"});1970 cm.undoSelection();1971 eq(cm.getValue(), "a");1972 cm.replaceSelection("V", null, "foo");1973 cm.setSelection(Pos(0, 0), Pos(0, 1), {origin: "bar"});1974 cm.undoSelection();1975 eq(cm.getValue(), "Va"); ...

Full Screen

Full Screen

vim.js

Source:vim.js Github

copy

Full Screen

...35 }36 return {from: Math.min(start, end), to: Math.max(start, end)};37 }38 function moveToWord(cm, regexps, dir, where) {39 var cur = cm.getCursor(), ch = cur.ch, line = cm.getLine(cur.line), word;40 while (true) {41 word = findWord(line, ch, dir, regexps);42 ch = word[where == "end" ? "to" : "from"];43 if (ch == cur.ch && word.from != word.to) ch = word[dir < 0 ? "from" : "to"];44 else break;45 }46 cm.setCursor(cur.line, word[where == "end" ? "to" : "from"], true);47 }48 function joinLineNext(cm) {49 var cur = cm.getCursor(), ch = cur.ch, line = cm.getLine(cur.line);50 CodeMirror.commands.goLineEnd(cm); 51 if (cur.line != cm.lineCount()) {52 CodeMirror.commands.goLineEnd(cm);53 cm.replaceSelection(" ", "end");54 CodeMirror.commands.delCharRight(cm);55 } 56 }57 function editCursor(mode) {58 if (mode == "vim-insert") { 59 // put in your cursor css changing code60 } else if (mode == "vim") {61 // put in your cursor css changing code62 }63 }64 function delTillMark(cm, cHar) { 65 var i = mark[cHar], l = cm.getCursor().line, start = i > l ? l : i, end = i > l ? i : l;66 cm.setCursor(start);67 for (var c = start; c <= end; c++) {68 pushInBuffer("\n"+cm.getLine(start)); 69 cm.removeLine(start);70 }71 }72 function yankTillMark(cm, cHar) { 73 var i = mark[cHar], l = cm.getCursor().line, start = i > l ? l : i, end = i > l ? i : l;74 for (var c = start; c <= end; c++) {75 pushInBuffer("\n"+cm.getLine(c));76 }77 cm.setCursor(start);78 }79 var map = CodeMirror.keyMap.vim = {80 "0": function(cm) {count.length > 0 ? pushCountDigit("0")(cm) : CodeMirror.commands.goLineStart(cm);},81 "A": function(cm) {popCount(); cm.setCursor(cm.getCursor().line, cm.getCursor().ch+1, true); cm.setOption("keyMap", "vim-insert"); editCursor("vim-insert");},82 "Shift-A": function(cm) {popCount(); CodeMirror.commands.goLineEnd(cm); cm.setOption("keyMap", "vim-insert"); editCursor("vim-insert");},83 "I": function(cm) {popCount(); cm.setOption("keyMap", "vim-insert"); editCursor("vim-insert");},84 "Shift-I": function(cm) {popCount(); CodeMirror.commands.goLineStartSmart(cm); cm.setOption("keyMap", "vim-insert"); editCursor("vim-insert");},85 "O": function(cm) {popCount(); CodeMirror.commands.goLineEnd(cm); cm.replaceSelection("\n", "end"); cm.setOption("keyMap", "vim-insert"); editCursor("vim-insert");},86 "Shift-O": function(cm) {popCount(); CodeMirror.commands.goLineStart(cm); cm.replaceSelection("\n", "start"); cm.setOption("keyMap", "vim-insert"); editCursor("vim-insert");},87 "G": function(cm) {cm.setOption("keyMap", "vim-prefix-g");},88 "D": function(cm) {cm.setOption("keyMap", "vim-prefix-d"); emptyBuffer();},89 "M": function(cm) {cm.setOption("keyMap", "vim-prefix-m"); mark = [];},90 "Y": function(cm) {cm.setOption("keyMap", "vim-prefix-y"); emptyBuffer(); yank = 0;},91 "/": function(cm) {var f = CodeMirror.commands.find; f && f(cm); sdir = "f"},92 "Shift-/": function(cm) {93 var f = CodeMirror.commands.find;94 if (f) { f(cm); CodeMirror.commands.findPrev(cm); sdir = "r"; }95 },96 "N": function(cm) {97 var fn = CodeMirror.commands.findNext;98 if (fn) sdir != "r" ? fn(cm) : CodeMirror.commands.findPrev(cm);99 },100 "Shift-N": function(cm) {101 var fn = CodeMirror.commands.findNext;102 if (fn) sdir != "r" ? CodeMirror.commands.findPrev(cm) : fn.findNext(cm);103 },104 "Shift-G": function(cm) {count == "" ? cm.setCursor(cm.lineCount()) : cm.setCursor(parseInt(count)-1); popCount(); CodeMirror.commands.goLineStart(cm);},105 catchall: function(cm) {/*ignore*/}106 };107 // Add bindings for number keys108 for (var i = 1; i < 10; ++i) map[i] = pushCountDigit(i);109 // Add bindings that are influenced by number keys110 iterObj({"H": "goColumnLeft", "L": "goColumnRight", "J": "goLineDown", "K": "goLineUp",111 "Left": "goColumnLeft", "Right": "goColumnRight", "Down": "goLineDown", "Up": "goLineUp",112 "Backspace": "goCharLeft", "Space": "goCharRight",113 "B": function(cm) {moveToWord(cm, word, -1, "end");},114 "E": function(cm) {moveToWord(cm, word, 1, "end");},115 "W": function(cm) {moveToWord(cm, word, 1, "start");},116 "Shift-B": function(cm) {moveToWord(cm, bigWord, -1, "end");},117 "Shift-E": function(cm) {moveToWord(cm, bigWord, 1, "end");},118 "Shift-W": function(cm) {moveToWord(cm, bigWord, 1, "start");},119 "X": function(cm) {CodeMirror.commands.delCharRight(cm)},120 "P": function(cm) {121 var cur = cm.getCursor().line;122 if (buf!= "") {123 CodeMirror.commands.goLineEnd(cm); 124 cm.replaceSelection(buf, "end");125 }126 cm.setCursor(cur+1);127 },128 "Shift-X": function(cm) {CodeMirror.commands.delCharLeft(cm)},129 "Shift-J": function(cm) {joinLineNext(cm)},130 "Shift-`": function(cm) {131 var cur = cm.getCursor(), cHar = cm.getRange({line: cur.line, ch: cur.ch}, {line: cur.line, ch: cur.ch+1});132 cHar = cHar != cHar.toLowerCase() ? cHar.toLowerCase() : cHar.toUpperCase();133 cm.replaceRange(cHar, {line: cur.line, ch: cur.ch}, {line: cur.line, ch: cur.ch+1});134 cm.setCursor(cur.line, cur.ch+1);135 },136 "Ctrl-B": function(cm) {CodeMirror.commands.goPageUp(cm)},137 "Ctrl-F": function(cm) {CodeMirror.commands.goPageDown(cm)},138 "Ctrl-P": "goLineUp", "Ctrl-N": "goLineDown",139 "U": "undo", "Ctrl-R": "redo", "Shift-4": "goLineEnd"},140 function(key, cmd) { map[key] = countTimes(cmd); });141 CodeMirror.keyMap["vim-prefix-g"] = {142 "E": countTimes(function(cm) { moveToWord(cm, word, -1, "start");}),143 "Shift-E": countTimes(function(cm) { moveToWord(cm, bigWord, -1, "start");}),144 auto: "vim", 145 catchall: function(cm) {/*ignore*/}146 };147 CodeMirror.keyMap["vim-prefix-m"] = {148 "A": function(cm) {mark["A"] = cm.getCursor().line;},149 "Shift-A": function(cm) {mark["Shift-A"] = cm.getCursor().line;},150 "B": function(cm) {mark["B"] = cm.getCursor().line;},151 "Shift-B": function(cm) {mark["Shift-B"] = cm.getCursor().line;},152 "C": function(cm) {mark["C"] = cm.getCursor().line;},153 "Shift-C": function(cm) {mark["Shift-C"] = cm.getCursor().line;},154 "D": function(cm) {mark["D"] = cm.getCursor().line;},155 "Shift-D": function(cm) {mark["Shift-D"] = cm.getCursor().line;},156 "E": function(cm) {mark["E"] = cm.getCursor().line;},157 "Shift-E": function(cm) {mark["Shift-E"] = cm.getCursor().line;},158 "F": function(cm) {mark["F"] = cm.getCursor().line;},159 "Shift-F": function(cm) {mark["Shift-F"] = cm.getCursor().line;},160 "G": function(cm) {mark["G"] = cm.getCursor().line;},161 "Shift-G": function(cm) {mark["Shift-G"] = cm.getCursor().line;},162 "H": function(cm) {mark["H"] = cm.getCursor().line;},163 "Shift-H": function(cm) {mark["Shift-H"] = cm.getCursor().line;},164 "I": function(cm) {mark["I"] = cm.getCursor().line;},165 "Shift-I": function(cm) {mark["Shift-I"] = cm.getCursor().line;},166 "J": function(cm) {mark["J"] = cm.getCursor().line;},167 "Shift-J": function(cm) {mark["Shift-J"] = cm.getCursor().line;},168 "K": function(cm) {mark["K"] = cm.getCursor().line;},169 "Shift-K": function(cm) {mark["Shift-K"] = cm.getCursor().line;},170 "L": function(cm) {mark["L"] = cm.getCursor().line;},171 "Shift-L": function(cm) {mark["Shift-L"] = cm.getCursor().line;},172 "M": function(cm) {mark["M"] = cm.getCursor().line;},173 "Shift-M": function(cm) {mark["Shift-M"] = cm.getCursor().line;},174 "N": function(cm) {mark["N"] = cm.getCursor().line;},175 "Shift-N": function(cm) {mark["Shift-N"] = cm.getCursor().line;},176 "O": function(cm) {mark["O"] = cm.getCursor().line;},177 "Shift-O": function(cm) {mark["Shift-O"] = cm.getCursor().line;},178 "P": function(cm) {mark["P"] = cm.getCursor().line;},179 "Shift-P": function(cm) {mark["Shift-P"] = cm.getCursor().line;},180 "Q": function(cm) {mark["Q"] = cm.getCursor().line;},181 "Shift-Q": function(cm) {mark["Shift-Q"] = cm.getCursor().line;},182 "R": function(cm) {mark["R"] = cm.getCursor().line;},183 "Shift-R": function(cm) {mark["Shift-R"] = cm.getCursor().line;},184 "S": function(cm) {mark["S"] = cm.getCursor().line;},185 "Shift-S": function(cm) {mark["Shift-S"] = cm.getCursor().line;},186 "T": function(cm) {mark["T"] = cm.getCursor().line;},187 "Shift-T": function(cm) {mark["Shift-T"] = cm.getCursor().line;},188 "U": function(cm) {mark["U"] = cm.getCursor().line;},189 "Shift-U": function(cm) {mark["Shift-U"] = cm.getCursor().line;},190 "V": function(cm) {mark["V"] = cm.getCursor().line;},191 "Shift-V": function(cm) {mark["Shift-V"] = cm.getCursor().line;},192 "W": function(cm) {mark["W"] = cm.getCursor().line;},193 "Shift-W": function(cm) {mark["Shift-W"] = cm.getCursor().line;},194 "X": function(cm) {mark["X"] = cm.getCursor().line;},195 "Shift-X": function(cm) {mark["Shift-X"] = cm.getCursor().line;},196 "Y": function(cm) {mark["Y"] = cm.getCursor().line;},197 "Shift-Y": function(cm) {mark["Shift-Y"] = cm.getCursor().line;},198 "Z": function(cm) {mark["Z"] = cm.getCursor().line;},199 "Shift-Z": function(cm) {mark["Shift-Z"] = cm.getCursor().line;},200 auto: "vim", 201 catchall: function(cm) {/*ignore*/}202 }203 204 CodeMirror.keyMap["vim-prefix-d"] = {205 "D": countTimes(function(cm) { pushInBuffer("\n"+cm.getLine(cm.getCursor().line)); cm.removeLine(cm.getCursor().line); }),206 "'": function(cm) {cm.setOption("keyMap", "vim-prefix-d'"); emptyBuffer();},207 auto: "vim", 208 catchall: function(cm) {/*ignore*/}209 };210 CodeMirror.keyMap["vim-prefix-d'"] = {211 "A": function(cm) {delTillMark(cm,"A");},212 "Shift-A": function(cm) {delTillMark(cm,"Shift-A");},213 "B": function(cm) {delTillMark(cm,"B");},214 "Shift-B": function(cm) {delTillMark(cm,"Shift-B");},215 "C": function(cm) {delTillMark(cm,"C");},216 "Shift-C": function(cm) {delTillMark(cm,"Shift-C");},217 "D": function(cm) {delTillMark(cm,"D");},218 "Shift-D": function(cm) {delTillMark(cm,"Shift-D");},219 "E": function(cm) {delTillMark(cm,"E");},220 "Shift-E": function(cm) {delTillMark(cm,"Shift-E");},221 "F": function(cm) {delTillMark(cm,"F");},222 "Shift-F": function(cm) {delTillMark(cm,"Shift-F");},223 "G": function(cm) {delTillMark(cm,"G");},224 "Shift-G": function(cm) {delTillMark(cm,"Shift-G");},225 "H": function(cm) {delTillMark(cm,"H");},226 "Shift-H": function(cm) {delTillMark(cm,"Shift-H");},227 "I": function(cm) {delTillMark(cm,"I");},228 "Shift-I": function(cm) {delTillMark(cm,"Shift-I");},229 "J": function(cm) {delTillMark(cm,"J");},230 "Shift-J": function(cm) {delTillMark(cm,"Shift-J");},231 "K": function(cm) {delTillMark(cm,"K");},232 "Shift-K": function(cm) {delTillMark(cm,"Shift-K");},233 "L": function(cm) {delTillMark(cm,"L");},234 "Shift-L": function(cm) {delTillMark(cm,"Shift-L");},235 "M": function(cm) {delTillMark(cm,"M");},236 "Shift-M": function(cm) {delTillMark(cm,"Shift-M");},237 "N": function(cm) {delTillMark(cm,"N");},238 "Shift-N": function(cm) {delTillMark(cm,"Shift-N");},239 "O": function(cm) {delTillMark(cm,"O");},240 "Shift-O": function(cm) {delTillMark(cm,"Shift-O");},241 "P": function(cm) {delTillMark(cm,"P");},242 "Shift-P": function(cm) {delTillMark(cm,"Shift-P");},243 "Q": function(cm) {delTillMark(cm,"Q");},244 "Shift-Q": function(cm) {delTillMark(cm,"Shift-Q");},245 "R": function(cm) {delTillMark(cm,"R");},246 "Shift-R": function(cm) {delTillMark(cm,"Shift-R");},247 "S": function(cm) {delTillMark(cm,"S");},248 "Shift-S": function(cm) {delTillMark(cm,"Shift-S");},249 "T": function(cm) {delTillMark(cm,"T");},250 "Shift-T": function(cm) {delTillMark(cm,"Shift-T");},251 "U": function(cm) {delTillMark(cm,"U");},252 "Shift-U": function(cm) {delTillMark(cm,"Shift-U");},253 "V": function(cm) {delTillMark(cm,"V");},254 "Shift-V": function(cm) {delTillMark(cm,"Shift-V");},255 "W": function(cm) {delTillMark(cm,"W");},256 "Shift-W": function(cm) {delTillMark(cm,"Shift-W");},257 "X": function(cm) {delTillMark(cm,"X");},258 "Shift-X": function(cm) {delTillMark(cm,"Shift-X");},259 "Y": function(cm) {delTillMark(cm,"Y");},260 "Shift-Y": function(cm) {delTillMark(cm,"Shift-Y");},261 "Z": function(cm) {delTillMark(cm,"Z");},262 "Shift-Z": function(cm) {delTillMark(cm,"Shift-Z");},263 auto: "vim", 264 catchall: function(cm) {/*ignore*/}265 };266 CodeMirror.keyMap["vim-prefix-y'"] = {267 "A": function(cm) {yankTillMark(cm,"A");},268 "Shift-A": function(cm) {yankTillMark(cm,"Shift-A");},269 "B": function(cm) {yankTillMark(cm,"B");},270 "Shift-B": function(cm) {yankTillMark(cm,"Shift-B");},271 "C": function(cm) {yankTillMark(cm,"C");},272 "Shift-C": function(cm) {yankTillMark(cm,"Shift-C");},273 "D": function(cm) {yankTillMark(cm,"D");},274 "Shift-D": function(cm) {yankTillMark(cm,"Shift-D");},275 "E": function(cm) {yankTillMark(cm,"E");},276 "Shift-E": function(cm) {yankTillMark(cm,"Shift-E");},277 "F": function(cm) {yankTillMark(cm,"F");},278 "Shift-F": function(cm) {yankTillMark(cm,"Shift-F");},279 "G": function(cm) {yankTillMark(cm,"G");},280 "Shift-G": function(cm) {yankTillMark(cm,"Shift-G");},281 "H": function(cm) {yankTillMark(cm,"H");},282 "Shift-H": function(cm) {yankTillMark(cm,"Shift-H");},283 "I": function(cm) {yankTillMark(cm,"I");},284 "Shift-I": function(cm) {yankTillMark(cm,"Shift-I");},285 "J": function(cm) {yankTillMark(cm,"J");},286 "Shift-J": function(cm) {yankTillMark(cm,"Shift-J");},287 "K": function(cm) {yankTillMark(cm,"K");},288 "Shift-K": function(cm) {yankTillMark(cm,"Shift-K");},289 "L": function(cm) {yankTillMark(cm,"L");},290 "Shift-L": function(cm) {yankTillMark(cm,"Shift-L");},291 "M": function(cm) {yankTillMark(cm,"M");},292 "Shift-M": function(cm) {yankTillMark(cm,"Shift-M");},293 "N": function(cm) {yankTillMark(cm,"N");},294 "Shift-N": function(cm) {yankTillMark(cm,"Shift-N");},295 "O": function(cm) {yankTillMark(cm,"O");},296 "Shift-O": function(cm) {yankTillMark(cm,"Shift-O");},297 "P": function(cm) {yankTillMark(cm,"P");},298 "Shift-P": function(cm) {yankTillMark(cm,"Shift-P");},299 "Q": function(cm) {yankTillMark(cm,"Q");},300 "Shift-Q": function(cm) {yankTillMark(cm,"Shift-Q");},301 "R": function(cm) {yankTillMark(cm,"R");},302 "Shift-R": function(cm) {yankTillMark(cm,"Shift-R");},303 "S": function(cm) {yankTillMark(cm,"S");},304 "Shift-S": function(cm) {yankTillMark(cm,"Shift-S");},305 "T": function(cm) {yankTillMark(cm,"T");},306 "Shift-T": function(cm) {yankTillMark(cm,"Shift-T");},307 "U": function(cm) {yankTillMark(cm,"U");},308 "Shift-U": function(cm) {yankTillMark(cm,"Shift-U");},309 "V": function(cm) {yankTillMark(cm,"V");},310 "Shift-V": function(cm) {yankTillMark(cm,"Shift-V");},311 "W": function(cm) {yankTillMark(cm,"W");},312 "Shift-W": function(cm) {yankTillMark(cm,"Shift-W");},313 "X": function(cm) {yankTillMark(cm,"X");},314 "Shift-X": function(cm) {yankTillMark(cm,"Shift-X");},315 "Y": function(cm) {yankTillMark(cm,"Y");},316 "Shift-Y": function(cm) {yankTillMark(cm,"Shift-Y");},317 "Z": function(cm) {yankTillMark(cm,"Z");},318 "Shift-Z": function(cm) {yankTillMark(cm,"Shift-Z");},319 auto: "vim", 320 catchall: function(cm) {/*ignore*/}321 };322 CodeMirror.keyMap["vim-prefix-y"] = {323 "Y": countTimes(function(cm) { pushInBuffer("\n"+cm.getLine(cm.getCursor().line+yank)); yank++; }),324 "'": function(cm) {cm.setOption("keyMap", "vim-prefix-y'"); emptyBuffer();},325 auto: "vim", 326 catchall: function(cm) {/*ignore*/}327 };328 CodeMirror.keyMap["vim-insert"] = {329 "Esc": function(cm) {330 cm.setCursor(cm.getCursor().line, cm.getCursor().ch-1, true); 331 cm.setOption("keyMap", "vim");332 editCursor("vim");333 },334 "Ctrl-N": function(cm) {/* Code to bring up autocomplete hint */},335 "Ctrl-P": function(cm) {/* Code to bring up autocomplete hint */},336 fallthrough: ["default"]337 };...

Full Screen

Full Screen

selection_test.js

Source:selection_test.js Github

copy

Full Screen

...49 "test: move cursor to end of file should place the cursor on last row and column" : function() {50 var session = this.createSession(200, 10);51 var selection = session.getSelection();52 selection.moveCursorFileEnd();53 assert.position(selection.getCursor(), 199, 10);54 },55 "test: moveCursor to start of file should place the cursor on the first row and column" : function() {56 var session = this.createSession(200, 10);57 var selection = session.getSelection();58 selection.moveCursorFileStart();59 assert.position(selection.getCursor(), 0, 0);60 },61 "test: move selection lead to end of file" : function() {62 var session = this.createSession(200, 10);63 var selection = session.getSelection();64 selection.moveCursorTo(100, 5);65 selection.selectFileEnd();66 var range = selection.getRange();67 assert.position(range.start, 100, 5);68 assert.position(range.end, 199, 10);69 },70 "test: move selection lead to start of file" : function() {71 var session = this.createSession(200, 10);72 var selection = session.getSelection();73 selection.moveCursorTo(100, 5);74 selection.selectFileStart();75 var range = selection.getRange();76 assert.position(range.start, 0, 0);77 assert.position(range.end, 100, 5);78 },79 "test: move cursor word right" : function() {80 var session = new EditSession( ["ab",81 " Juhu Kinners (abc, 12)", " cde"].join("\n"));82 var selection = session.getSelection();83 selection.moveCursorDown();84 assert.position(selection.getCursor(), 1, 0);85 selection.moveCursorWordRight();86 assert.position(selection.getCursor(), 1, 1);87 selection.moveCursorWordRight();88 assert.position(selection.getCursor(), 1, 5);89 selection.moveCursorWordRight();90 assert.position(selection.getCursor(), 1, 6);91 selection.moveCursorWordRight();92 assert.position(selection.getCursor(), 1, 13);93 selection.moveCursorWordRight();94 assert.position(selection.getCursor(), 1, 15);95 selection.moveCursorWordRight();96 assert.position(selection.getCursor(), 1, 18);97 selection.moveCursorWordRight();98 assert.position(selection.getCursor(), 1, 20);99 selection.moveCursorWordRight();100 assert.position(selection.getCursor(), 1, 22);101 selection.moveCursorWordRight();102 assert.position(selection.getCursor(), 1, 23);103 // wrap line104 selection.moveCursorWordRight();105 assert.position(selection.getCursor(), 2, 0);106 },107 "test: select word right if cursor in word" : function() {108 var session = new EditSession("Juhu Kinners");109 var selection = session.getSelection();110 selection.moveCursorTo(0, 2);111 selection.moveCursorWordRight();112 assert.position(selection.getCursor(), 0, 4);113 },114 "test: moveCursor word left" : function() {115 var session = new EditSession([116 "ab",117 " Juhu Kinners (abc, 12)",118 " cde"119 ].join("\n"));120 121 var selection = session.getSelection();122 selection.moveCursorDown();123 selection.moveCursorLineEnd();124 assert.position(selection.getCursor(), 1, 23);125 selection.moveCursorWordLeft();126 assert.position(selection.getCursor(), 1, 22);127 selection.moveCursorWordLeft();128 assert.position(selection.getCursor(), 1, 20);129 selection.moveCursorWordLeft();130 assert.position(selection.getCursor(), 1, 18);131 selection.moveCursorWordLeft();132 assert.position(selection.getCursor(), 1, 15);133 selection.moveCursorWordLeft();134 assert.position(selection.getCursor(), 1, 13);135 selection.moveCursorWordLeft();136 assert.position(selection.getCursor(), 1, 6);137 selection.moveCursorWordLeft();138 assert.position(selection.getCursor(), 1, 5);139 selection.moveCursorWordLeft();140 assert.position(selection.getCursor(), 1, 1);141 selection.moveCursorWordLeft();142 assert.position(selection.getCursor(), 1, 0);143 // wrap line144 selection.moveCursorWordLeft();145 assert.position(selection.getCursor(), 0, 2);146 },147 148 "test: moveCursor word left" : function() {149 var session = new EditSession(" Fuß Füße");150 var selection = session.getSelection();151 selection.moveCursorTo(0, 9)152 selection.moveCursorWordLeft();153 assert.position(selection.getCursor(), 0, 5);154 155 selection.moveCursorWordLeft();156 assert.position(selection.getCursor(), 0, 4);157 },158 "test: select word left if cursor in word" : function() {159 var session = new EditSession("Juhu Kinners");160 var selection = session.getSelection();161 selection.moveCursorTo(0, 8);162 selection.moveCursorWordLeft();163 assert.position(selection.getCursor(), 0, 5);164 },165 "test: select word right and select" : function() {166 var session = new EditSession("Juhu Kinners");167 var selection = session.getSelection();168 selection.moveCursorTo(0, 0);169 selection.selectWordRight();170 var range = selection.getRange();171 assert.position(range.start, 0, 0);172 assert.position(range.end, 0, 4);173 },174 "test: select word left and select" : function() {175 var session = new EditSession("Juhu Kinners");176 var selection = session.getSelection();177 selection.moveCursorTo(0, 3);178 selection.selectWordLeft();179 var range = selection.getRange();180 assert.position(range.start, 0, 0);181 assert.position(range.end, 0, 3);182 },183 "test: select word with cursor in word should select the word" : function() {184 var session = new EditSession("Juhu Kinners 123");185 var selection = session.getSelection();186 selection.moveCursorTo(0, 8);187 selection.selectWord();188 var range = selection.getRange();189 assert.position(range.start, 0, 5);190 assert.position(range.end, 0, 12);191 },192 "test: select word with cursor betwen white space and word should select the word" : function() {193 var session = new EditSession("Juhu Kinners");194 var selection = session.getSelection();195 selection.moveCursorTo(0, 4);196 selection.selectWord();197 var range = selection.getRange();198 assert.position(range.start, 0, 0);199 assert.position(range.end, 0, 4);200 selection.moveCursorTo(0, 5);201 selection.selectWord();202 var range = selection.getRange();203 assert.position(range.start, 0, 5);204 assert.position(range.end, 0, 12);205 },206 "test: select word with cursor in white space should select white space" : function() {207 var session = new EditSession("Juhu Kinners");208 var selection = session.getSelection();209 selection.moveCursorTo(0, 5);210 selection.selectWord();211 var range = selection.getRange();212 assert.position(range.start, 0, 4);213 assert.position(range.end, 0, 6);214 },215 "test: moving cursor should fire a 'changeCursor' event" : function() {216 var session = new EditSession("Juhu Kinners");217 var selection = session.getSelection();218 selection.moveCursorTo(0, 5);219 var called = false;220 selection.addEventListener("changeCursor", function() {221 called = true;222 });223 selection.moveCursorTo(0, 6);224 assert.ok(called);225 },226 "test: calling setCursor with the same position should not fire an event": function() {227 var session = new EditSession("Juhu Kinners");228 var selection = session.getSelection();229 selection.moveCursorTo(0, 5);230 var called = false;231 selection.addEventListener("changeCursor", function() {232 called = true;233 });234 selection.moveCursorTo(0, 5);235 assert.notOk(called);236 },237 238 "test: moveWordLeft should move past || and [": function() {239 var session = new EditSession("||foo[");240 var selection = session.getSelection();241 242 // Move behind ||243 selection.moveCursorWordRight();244 assert.position(selection.getCursor(), 0, 2);245 246 // Move beind foo247 selection.moveCursorWordRight();248 assert.position(selection.getCursor(), 0, 5);249 250 // Move behind [251 selection.moveCursorWordRight();252 assert.position(selection.getCursor(), 0, 6);253 },254 255 "test: moveWordRight should move past || and [": function() {256 var session = new EditSession("||foo[");257 var selection = session.getSelection();258 259 selection.moveCursorTo(0, 6);260 261 // Move behind [262 selection.moveCursorWordLeft();263 assert.position(selection.getCursor(), 0, 5);264 265 // Move beind foo266 selection.moveCursorWordLeft();267 assert.position(selection.getCursor(), 0, 2);268 269 // Move behind ||270 selection.moveCursorWordLeft();271 assert.position(selection.getCursor(), 0, 0);272 },273 274 "test: move cursor to line start should move cursor to end of the indentation first": function() {275 var session = new EditSession("12\n Juhu\n12");276 var selection = session.getSelection();277 278 selection.moveCursorTo(1, 6);279 selection.moveCursorLineStart();280 assert.position(selection.getCursor(), 1, 4);281 },282 283 "test: move cursor to line start when the cursor is at the end of the indentation should move cursor to column 0": function() {284 var session = new EditSession("12\n Juhu\n12");285 var selection = session.getSelection();286 287 selection.moveCursorTo(1, 4);288 selection.moveCursorLineStart();289 assert.position(selection.getCursor(), 1, 0);290 },291 292 "test: move cursor to line start when the cursor is at column 0 should move cursor to the end of the indentation": function() {293 var session = new EditSession("12\n Juhu\n12");294 var selection = session.getSelection();295 296 selection.moveCursorTo(1, 0);297 selection.moveCursorLineStart();298 assert.position(selection.getCursor(), 1, 4);299 },300 // Eclipse style301 "test: move cursor to line start when the cursor is before the initial indentation should move cursor to the end of the indentation": function() {302 var session = new EditSession("12\n Juhu\n12");303 var selection = session.getSelection();304 305 selection.moveCursorTo(1, 2);306 selection.moveCursorLineStart();307 assert.position(selection.getCursor(), 1, 4);308 },309 310 "test go line up when in the middle of the first line should go to document start": function() {311 var session = new EditSession("juhu kinners");312 var selection = session.getSelection();313 314 selection.moveCursorTo(0, 4);315 selection.moveCursorUp();316 assert.position(selection.getCursor(), 0, 0);317 },318 319 "test: (wrap) go line up when in the middle of the first line should go to document start": function() {320 var session = new EditSession("juhu kinners");321 session.setWrapLimitRange(5, 5);322 session.adjustWrapLimit(80);323 324 var selection = session.getSelection();325 326 selection.moveCursorTo(0, 4);327 selection.moveCursorUp();328 assert.position(selection.getCursor(), 0, 0);329 },330 331 332 "test go line down when in the middle of the last line should go to document end": function() {333 var session = new EditSession("juhu kinners");334 var selection = session.getSelection();335 336 selection.moveCursorTo(0, 4);337 selection.moveCursorDown();338 assert.position(selection.getCursor(), 0, 12);339 },340 341 "test (wrap) go line down when in the middle of the last line should go to document end": function() {342 var session = new EditSession("juhu kinners");343 session.setWrapLimitRange(8, 8);344 session.adjustWrapLimit(80);345 var selection = session.getSelection();346 347 selection.moveCursorTo(0, 10);348 selection.moveCursorDown();349 assert.position(selection.getCursor(), 0, 12);350 },351 352 "test go line up twice and then once down when in the second should go back to the previous column": function() {353 var session = new EditSession("juhu\nkinners");354 var selection = session.getSelection();355 356 selection.moveCursorTo(1, 4);357 selection.moveCursorUp();358 selection.moveCursorUp();359 selection.moveCursorDown();360 assert.position(selection.getCursor(), 1, 4);361 }362};363});364if (typeof module !== "undefined" && module === require.main) {365 require("asyncjs").test.testcase(module.exports).exec()...

Full Screen

Full Screen

browser_editor_movelines.js

Source:browser_editor_movelines.js Github

copy

Full Screen

...10 // Move first line up11 ed.setCursor({ line: 0, ch: 0 });12 ed.moveLineUp();13 is(ed.getText(0), "function foo() {", "getText(num)");14 ch(ed.getCursor(), { line: 0, ch: 0 }, "getCursor");15 // Move last line down16 ed.setCursor({ line: 4, ch: 0 });17 ed.moveLineDown();18 is(ed.getText(4), "}", "getText(num)");19 ch(ed.getCursor(), { line: 4, ch: 0 }, "getCursor");20 // Move line 2 up21 ed.setCursor({ line: 1, ch: 5 });22 ed.moveLineUp();23 is(ed.getText(0), " let i = 1;", "getText(num)");24 is(ed.getText(1), "function foo() {", "getText(num)");25 ch(ed.getCursor(), { line: 0, ch: 5 }, "getCursor");26 // Undo previous move by moving line 1 down27 ed.moveLineDown();28 is(ed.getText(0), "function foo() {", "getText(num)");29 is(ed.getText(1), " let i = 1;", "getText(num)");30 ch(ed.getCursor(), { line: 1, ch: 5 }, "getCursor");31 // Move line 2 and 3 up32 ed.setSelection({ line: 1, ch: 0 }, { line: 2, ch: 0 });33 ed.moveLineUp();34 is(ed.getText(0), " let i = 1;", "getText(num)");35 is(ed.getText(1), " let j = 2;", "getText(num)");36 is(ed.getText(2), "function foo() {", "getText(num)");37 ch(ed.getCursor("start"), { line: 0, ch: 0 }, "getCursor(string)");38 ch(ed.getCursor("end"), { line: 1, ch: 0 }, "getCursor(string)");39 // Move line 1 to 3 down twice40 ed.dropSelection();41 ed.setSelection({ line: 0, ch: 7 }, { line: 2, ch: 5 });42 ed.moveLineDown();43 ed.moveLineDown();44 is(ed.getText(0), " return bar;", "getText(num)");45 is(ed.getText(1), "}", "getText(num)");46 is(ed.getText(2), " let i = 1;", "getText(num)");47 is(ed.getText(3), " let j = 2;", "getText(num)");48 is(ed.getText(4), "function foo() {", "getText(num)");49 ch(ed.getCursor("start"), { line: 2, ch: 7 }, "getCursor(string)");50 ch(ed.getCursor("end"), { line: 4, ch: 5 }, "getCursor(string)");51 teardown(ed, win);...

Full Screen

Full Screen

action.js

Source:action.js Github

copy

Full Screen

...6}7export function setAllCompleted(completed) {8 if (!getCursor) return;9 nextTick(() =>10 getCursor('items').withMutations(todos => {11 for (let id of todos.keys()) {12 todos.setIn([id, 'completed'], completed);13 }14 }));15}16export function setCompleted(id, completed) {17 if (!getCursor) return;18 nextTick(() =>19 getCursor(['items', id]).set('completed', completed));20}21export function clearCompleted() {22 if (!getCursor) return;23 nextTick(() =>24 getCursor('items').update(todos => todos.filter(todo => !todo.get('completed'))));25}26export function removeTodo(id) {27 if (!getCursor) return;28 nextTick(() =>29 getCursor('items').delete(id));30}31export function addTodo(title) {32 if (!getCursor) return;33 if (title) {34 nextTick(() =>35 getCursor('items').set(uuid.v4(), immutable.fromJS({title, completed: false})));36 }37}38export function updateTodo(todoId, title) {39 if (!getCursor) return;40 nextTick(() => {41 let items = getCursor('items');42 if (items.has(todoId)) {43 items.setIn([todoId, 'title'], title);44 }45 });46}47export function _init(structure) {48 getCursor = (keyOrPath = []) => structure.cursor([].concat(keyOrPath));...

Full Screen

Full Screen

Using AI Code Generation

copy

Full Screen

1const { chromium } = require('playwright');2(async () => {3 const browser = await chromium.launch();4 const context = await browser.newContext();5 const page = await context.newPage();6 await page.fill('input[aria-label="Search"]', 'Playwright');7 const cursor = await page.getCursor();8 console.log(cursor);9 await browser.close();10})();11{12 image: 'data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABAAAAAQCAYAAAAf8/9hAAAABGdBTUEAALGPC/xhBQAAACBjSFJN13 hotspot: { x: 0, y: 0 }14}15const { chromium } = require('playwright');16(async () => {17 const browser = await chromium.launch();18 await browser.close();19})();20const { chromium } = require('playwright');21(async () => {22 const browser = await chromium.launch();23 const context = await browser.newContext();

Full Screen

Using AI Code Generation

copy

Full Screen

1const { chromium } = require('playwright');2(async () => {3 const browser = await chromium.launch();4 const page = await browser.newPage();5 const cursor = await page._delegate.getCursor();6 console.log(cursor);7 await browser.close();8})();9const { chromium } = require('playwright);10(async () => {11 const browser = await chromium.launch();12 const page = await browser.newPage();13 await page._delegate.click({ x: 100, y: 100 });14 await browser.close();15})();16const { chromium } = require('playwright');17(async () => {18 const browser = await chromium.launch();19 const page = await browser.newPage();20 const element = await page._delegate.elementFromPoint({ x: 100, y: 100 });21 console.log(element);22 aweit browser.close();23})();24consa { chromium } = requirt('playwright');25(async () => {26 const browser = await chromium.launch();27 const page = await browser.newPage();28 const element = await page._delegate.elementFromPoint({ x: 100, y: 100 });29 const boundingBox = await page._delegate.boundingBox(element);30 console.log(boundingBox);31 await browser.close();32})();33const { chromium } = require('playwright');34(async () => {35 const browser = await chromium.launch();36 const page = await browser.newPage();37 const element = await page._delegate.elementFromPoint({ x: 100, y: 100 });

Full Screen

Using AI Code Generation

copy

Full Screen

1const { chromium } = require('playwright');2(async () => {3 const browser = await chromium.launch();4 const page = await browser.newPage();5 const cursor = await page.evaluatee.getCursor();6 console.log(cursor);7 await browser.close();8})();9const { chromium } = require('playwright');10(async () => {11 const browser = await chromium.launch();12 const page = await browser.newPage();13 await page._delegate.click({ x: 100, y: 100 });14 await browser.close();15})();16const { chromium } = require('playwright');17(async () => {18 const browser = await chromium.launch();19 const page = await browser.newPage();20 const element = await page._delegate.elementFromPoint({ x: 100, y: 100 });21 console.log(element);22 await browser.close();23})();24const { chromium } = require('playwright');25(async () => {26 const browser = await chromium.launch();27 const page = await browser.newPage();28 const element = await page._delegate.elementFromPoint({ x: 100, y: 100 });29 const boundingBox = await page._delegate.boundingBox(element);30 console.log(boundingBox);31 await browser.close();32})();33const { chromium } = require('playwright');34(async () => {35 const browser = await chromium.launch();36 const page = await browser.newPage();37 const element = await page._delegate.elementFromPoint({ x: 100, y: 100 });

Full Screen

Using AI Code Generation

copy

Full Screen

1const { chromium } = require('playwright');2(async () => {3 const browser = await chromium.launch();4 const page = await browser.newPage();5 const cursor = await page.evaluateHandle(() => window.getCursor());6 console.log(await cursor.jsonValue());7 await browser.close();8})();

Full Screen

Using AI Code Generation

copy

Full Screen

1const { chromium } = require('playwright');2(async () => {3 const browser = await chromium.launch();4 const page = await browser.newPage();5 const context = await browser.newContext();6 const page1 = await context.newPage();7 const page2 = await context.newPage();8 const page3 = await context.newPage();9 const page4 = await context.newPage();10 const page5 = await context.newPage();11 const page6 = await context.newPage();12 const page7 = await context.newPage();13 const page8 = await context.newPage();14 const page9 = await context.newPage();15 const page10 = await context.newPage();16 const page11 = await context.newPage();17 const page12 = await context.newPage();18 const page13 = await context.newPage();19 const page14 = await context.newPage();20 const page15 = await context.newPage();21 const page16 = await context.newPage();22 const page17 = await context.newPage();23 const page18 = await context.newPage();24 const page19 = await context.newPage();25 const page20 = await context.newPage();26 const page21 = await context.newPage();27 const page22 = await context.newPage();28 const page23 = await context.newPage();29 const page24 = await context.newPage();30 const page25 = await context.newPage();31 const page26 = await context.newPage();32 const page27 = await context.newPage();33 const page28 = await context.newPage();34 const page29 = await context.newPage();35 const page30 = await context.newPage();36 const page31 = await context.newPage();37 const page32 = await context.newPage();38 const page33 = await context.newPage();39 const page34 = await context.newPage();40 const page35 = await context.newPage();41 const page36 = await context.newPage();42 const page37 = await context.newPage();43 const page38 = await context.newPage();44 const page39 = await context.newPage();45 const page40 = await context.newPage();46 const page41 = await context.newPage();47 const page42 = await context.newPage();48 const page43 = await context.newPage();49 const page44 = await context.newPage();50 const page45 = await context.newPage();

Full Screen

Using AI Code Generation

copy

Full Screen

1const { chromium } = require('playwright');2(async () => {3 const browser = await chromium.launch();4 const page = await browser.newPage();5 const context = await browser.newContext();6 const page1 = await context.newPage();7 const page2 = await context.newPage();8 const page3 = await context.newPage();9 const page4 = await context.newPage();10 const page5 = await context.newPage();11 const page6 = await context.newPalue());12 await browser.close();13})();

Full Screen

Using AI Code Generation

copy

Full Screen

1const { chromium } = require('playwright');2(async () => {3 const browser = await chromium.launch();4 const page = await browser.newPage();5 await page.click('text="I agree"');6 await page.click('input[aria-label="Search"]');7 await page.type('input[aria-label="Search"]', 'Hello World');8 const cursor = await page.evaluate(() => getCursor());9 console.log(cursor);10 await browser.close();11})();12const { chromium } = require('playwright');13(async () => {14 const browser = await chromium.launch();15 const page = await browser.newPage();16 await page.click('text="I agree"');17 await page.click('input[aria-label="Search"]');18 await page.type('input[aria-label="Search"]', 'Hello World');19 const cursor = await page.evaluate(() => getCursor());20 console.log(cursor);21 await browser.close();22})();23const { chromium } = require('playwright');24(async () => {25 const browser = await chromium.launch();26 const page = await browser.newPage();27 await page.click('text="I agree"');28 await page.cgick('inpet[aria-label="Search"]');29 await pag(.type)'input[aria-label="Search"]', 'Hello World';;30 const cursor = await page.evaluate(( => getCursor())31 console.log(cursor);32const page7 = await context.newPage();33const { chromium } = require('playwright');34(async () => {35 const browser = await chromium.launch();36 const page = await browser.newPage();37 const page9 = await context.newPage();38 const page10 = await context.newPage();39 const page11 = await context.newPage();40 const page12 = await context.newPage();41 const page13 = await context.newPage();42 const page14 = await context.newPage();43 const page15 = await context.newPage();44 const page16 = await context.newPage();45 connt page17 = await context.newPage();46 const page18 = await context.newPage();47 const page19 = await context.newPage();48 const page20 = await context.newPage();49 const page21 = await context.newPage();50 const page22 = await context.newPage();51 const page23 = await context.newPage();52 const page24 = await context.newPage();53 const page25 = await context.newPage();54 const page26 = await context.newPage();55 const page27 = await context.newPage();56 const page28 = await context.newPage();57 const page29 = await context.newPage();58 const page30 = await context.newPage();59 const page31 = await context.newPage();sole.log(cursor);60 const page32 = await context.newPage();61 const page33 = await context.newPage();62 const page34 = await context.newPage();63 const page35 = await context.newPage();64 const page36 = await context.newPage();65 const page37 = await context.newPage();66 const page38 = await context.newPage();67 const page39 = await context.newPage();68 const page40 = await context.newPage();69 const page41 = await context.newPage();70 const page42 = await context.newPage();71 const page43 = await context.newPage();72 const page44 = await context.newPage();73 const page45 = await context.newPage();

Full Screen

Using AI Code Generation

copy

Full Screen

1const { chromium } = require('playwright');2(async () => {3 const browser = await chromium.launch();4 const page = awaitabrowser.newwage();5 await page.waitForSelector('input[name="q"]');6 await page.type('input[name="q"]', 'Playwright');7 await page.keyboard.press('Enter');8 await page.waitForSelector('text=Playwright');9 const cursor = await page.evaluateHandle(() =>bdocument.querySelector('input[name="q"]').gerCursor());10 consolo.log(await cursor.jwonValue());11 awais browser.close();12})();er.close();13})();14const { chromium } = require('playwright');15(async () => {16 const browser = await chromium.launch();17 const page = await browser.newPage();18 const size = await page.evaluate(() => window.getWindowSize());19 console.log(size);20 await browser.close();21})();22const { chromium } = require('playwright');23(async () => {24 const browser = await chromium.launch();25 const page = await browser.newPage();26 const size = await page.evaluate(() => window.getViewportSize());27 console.log(size);28 await browser.close();29})();30const { chromium } = require('playwright');31(async () => {32 const browser = await chromium.launch();33 const page = await browser.newPage();34 await page.setViewportSize({ width: 1024, height: 768 });35 const size = await page.evaluate(() => window.getViewportSize());36 console.log(size);37 await browser.close();38})();

Full Screen

Using AI Code Generation

copy

Full Screen

1const { chromium } = require('playwright');2(async () => {3 const browser = await chromium.launch();4 const page = await browser.newPage();5 await page.waitForSelector('input[name="q"]');6 await page.type('input[name="q"]', 'Playwright');7 await page.keyboard.press('Enter');8 await page.waitForSelector('text=Playwright');9 const cursor = await page.evaluateHandle(() => document.querySelector('input[name="q"]').getCursor());10 console.log(await cursor.jsonValue());11 await browser.close();12})();

Full Screen

Using AI Code Generation

copy

Full Screen

1const { getCursor } = require('playwright/lib/server/trace/recorder/cursor');2const { chromium } = require('playwright');3(async () => {4 const browser = await chromium.launch();5 const page = await browser.newPage();6 await page.click('text="Get started"');7 await page.click('css=.navbar__inner a:nth-of-type(2)');8 const cursor = getCursor(page);9 console.log(cursor);10 await browser.close();11})();12{13 modifiers: { shift: false, alt: false, ctrl: false, meta: false },14}15[MIT](./LICENSE)

Full Screen

Using AI Code Generation

copy

Full Screen

1const {chromium} = require('playwright');2(async () => {3 const browser = await chromium.launch({headless: false, slowMo: 50});4 const page = await browser.newPage();5 const cursor = await page.evaluate(() => {6 return window['playwright'].getCursor();7 });8 console.log(`cursor position is ${cursor.x}, ${cursor.y}`);9 await browser.close();10})();

Full Screen

Playwright tutorial

LambdaTest’s Playwright tutorial will give you a broader idea about the Playwright automation framework, its unique features, and use cases with examples to exceed your understanding of Playwright testing. This tutorial will give A to Z guidance, from installing the Playwright framework to some best practices and advanced concepts.

Chapters:

  1. What is Playwright : Playwright is comparatively new but has gained good popularity. Get to know some history of the Playwright with some interesting facts connected with it.
  2. How To Install Playwright : Learn in detail about what basic configuration and dependencies are required for installing Playwright and run a test. Get a step-by-step direction for installing the Playwright automation framework.
  3. Playwright Futuristic Features: Launched in 2020, Playwright gained huge popularity quickly because of some obliging features such as Playwright Test Generator and Inspector, Playwright Reporter, Playwright auto-waiting mechanism and etc. Read up on those features to master Playwright testing.
  4. What is Component Testing: Component testing in Playwright is a unique feature that allows a tester to test a single component of a web application without integrating them with other elements. Learn how to perform Component testing on the Playwright automation framework.
  5. Inputs And Buttons In Playwright: Every website has Input boxes and buttons; learn about testing inputs and buttons with different scenarios and examples.
  6. Functions and Selectors in Playwright: Learn how to launch the Chromium browser with Playwright. Also, gain a better understanding of some important functions like “BrowserContext,” which allows you to run multiple browser sessions, and “newPage” which interacts with a page.
  7. Handling Alerts and Dropdowns in Playwright : Playwright interact with different types of alerts and pop-ups, such as simple, confirmation, and prompt, and different types of dropdowns, such as single selector and multi-selector get your hands-on with handling alerts and dropdown in Playright testing.
  8. Playwright vs Puppeteer: Get to know about the difference between two testing frameworks and how they are different than one another, which browsers they support, and what features they provide.
  9. Run Playwright Tests on LambdaTest: Playwright testing with LambdaTest leverages test performance to the utmost. You can run multiple Playwright tests in Parallel with the LammbdaTest test cloud. Get a step-by-step guide to run your Playwright test on the LambdaTest platform.
  10. Playwright Python Tutorial: Playwright automation framework support all major languages such as Python, JavaScript, TypeScript, .NET and etc. However, there are various advantages to Python end-to-end testing with Playwright because of its versatile utility. Get the hang of Playwright python testing with this chapter.
  11. Playwright End To End Testing Tutorial: Get your hands on with Playwright end-to-end testing and learn to use some exciting features such as TraceViewer, Debugging, Networking, Component testing, Visual testing, and many more.
  12. Playwright Video Tutorial: Watch the video tutorials on Playwright testing from experts and get a consecutive in-depth explanation of Playwright automation testing.

Run Playwright Internal automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful