tor-browser

The Tor Browser
git clone https://git.dasho.dev/tor-browser.git
Log | Files | Refs | README | LICENSE

browser_editor_movelines.js (2164B)


      1 /* Any copyright is dedicated to the Public Domain.
      2   http://creativecommons.org/publicdomain/zero/1.0/ */
      3 
      4 "use strict";
      5 
      6 async function test() {
      7  waitForExplicitFinish();
      8  const { ed, win } = await setup();
      9  const simpleProg =
     10    "function foo() {\n  let i = 1;\n  let j = 2;\n  " + "return bar;\n}";
     11  ed.setText(simpleProg);
     12 
     13  // Move first line up
     14  ed.setCursor({ line: 0, ch: 0 });
     15  ed.moveLineUp();
     16  is(ed.getText(0), "function foo() {", "getText(num)");
     17  ch(ed.getCursor(), { line: 0, ch: 0 }, "getCursor");
     18 
     19  // Move last line down
     20  ed.setCursor({ line: 4, ch: 0 });
     21  ed.moveLineDown();
     22  is(ed.getText(4), "}", "getText(num)");
     23  ch(ed.getCursor(), { line: 4, ch: 0 }, "getCursor");
     24 
     25  // Move line 2 up
     26  ed.setCursor({ line: 1, ch: 5 });
     27  ed.moveLineUp();
     28  is(ed.getText(0), "  let i = 1;", "getText(num)");
     29  is(ed.getText(1), "function foo() {", "getText(num)");
     30  ch(ed.getCursor(), { line: 0, ch: 5 }, "getCursor");
     31 
     32  // Undo previous move by moving line 1 down
     33  ed.moveLineDown();
     34  is(ed.getText(0), "function foo() {", "getText(num)");
     35  is(ed.getText(1), "  let i = 1;", "getText(num)");
     36  ch(ed.getCursor(), { line: 1, ch: 5 }, "getCursor");
     37 
     38  // Move line 2 and 3 up
     39  ed.setSelection({ line: 1, ch: 0 }, { line: 2, ch: 0 });
     40  ed.moveLineUp();
     41  is(ed.getText(0), "  let i = 1;", "getText(num)");
     42  is(ed.getText(1), "  let j = 2;", "getText(num)");
     43  is(ed.getText(2), "function foo() {", "getText(num)");
     44  ch(ed.getCursor("start"), { line: 0, ch: 0 }, "getCursor(string)");
     45  ch(ed.getCursor("end"), { line: 1, ch: 0 }, "getCursor(string)");
     46 
     47  // Move line 1 to 3 down twice
     48  ed.dropSelection();
     49  ed.setSelection({ line: 0, ch: 7 }, { line: 2, ch: 5 });
     50  ed.moveLineDown();
     51  ed.moveLineDown();
     52  is(ed.getText(0), "  return bar;", "getText(num)");
     53  is(ed.getText(1), "}", "getText(num)");
     54  is(ed.getText(2), "  let i = 1;", "getText(num)");
     55  is(ed.getText(3), "  let j = 2;", "getText(num)");
     56  is(ed.getText(4), "function foo() {", "getText(num)");
     57  ch(ed.getCursor("start"), { line: 2, ch: 7 }, "getCursor(string)");
     58  ch(ed.getCursor("end"), { line: 4, ch: 5 }, "getCursor(string)");
     59 
     60  teardown(ed, win);
     61 }