tor-browser

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

browser_editor_cursor.js (1572B)


      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  ch(ed.getCursor(), { line: 0, ch: 0 }, "default cursor position is ok");
     10  ed.setText("Hello.\nHow are you?");
     11 
     12  ed.setCursor({ line: 1, ch: 5 });
     13  ch(ed.getCursor(), { line: 1, ch: 5 }, "setCursor({ line, ch })");
     14 
     15  ch(ed.getPosition(7), { line: 1, ch: 0 }, "getPosition(num)");
     16  ch(ed.getPosition(7, 1)[0], { line: 1, ch: 0 }, "getPosition(num, num)[0]");
     17  ch(ed.getPosition(7, 1)[1], { line: 0, ch: 1 }, "getPosition(num, num)[1]");
     18 
     19  ch(ed.getOffset({ line: 1, ch: 0 }), 7, "getOffset(num)");
     20  ch(
     21    ed.getOffset({ line: 1, ch: 0 }, { line: 0, ch: 1 })[0],
     22    7,
     23    "getOffset(num, num)[0]"
     24  );
     25  ch(
     26    ed.getOffset({ line: 1, ch: 0 }, { line: 0, ch: 1 })[0],
     27    2,
     28    "getOffset(num, num)[1]"
     29  );
     30 
     31  is(ed.getSelection(), "", "nothing is selected");
     32  ed.setSelection({ line: 0, ch: 0 }, { line: 0, ch: 5 });
     33  is(ed.getSelection(), "Hello", "setSelection");
     34 
     35  ed.dropSelection();
     36  is(ed.getSelection(), "", "dropSelection");
     37 
     38  // Check that shift-click on a gutter selects the whole line (bug 919707)
     39  const iframe = win.document.querySelector("iframe");
     40  const gutter = iframe.contentWindow.document.querySelector(
     41    ".CodeMirror-gutters"
     42  );
     43 
     44  EventUtils.sendMouseEvent(
     45    { type: "mousedown", shiftKey: true },
     46    gutter,
     47    iframe.contentWindow
     48  );
     49  is(ed.getSelection(), "", "shift-click");
     50 
     51  teardown(ed, win);
     52 }