Example #1
0
 it("returns false when the two ranges differ in end positions", () => {
   const range = new DLocRange(loc, loc);
   const range2 = new DLocRange(DLoc.mustMakeDLoc(root, a, 0),
                                DLoc.mustMakeDLoc(root, a, 1));
   assert.isTrue(range.start.equals(range2.start));
   assert.isFalse(range.end.equals(range2.end));
   assert.isFalse(range.equals(range2));
 });
Example #2
0
    describe("contains", () => {
      let range: DLocRange;
      before(() => {
        range = new DLocRange(loc, loc.makeWithOffset(2));
      });

      it("returns false if the location is before the range", () => {
        assert.isFalse(range.contains(loc.make(loc.node.parentNode!, 0)));
      });

      it("returns false if the location is after the range", () => {
        assert.isFalse(range.contains(loc.makeWithOffset(3)));
      });

      it("returns true if the location is at start of the range", () => {
        assert.isTrue(range.contains(loc.makeWithOffset(0)));
      });

      it("returns true if the location is at end of the range", () => {
        assert.isTrue(range.contains(loc.makeWithOffset(2)));
      });

      it("returns true if the location is between the ends", () => {
        assert.isTrue(range.contains(loc.makeWithOffset(1)));
      });
    });
Example #3
0
  beforeEach(() => {
    dataRoot = editor.dataRoot;
    caretManager = editor.caretManager;

    ps = Array.from(dataRoot.querySelectorAll("body p"));
    firstBodyP = ps[0];
    firstBodyPLocation = caretManager.mustFromDataLocation(
      DLoc.mustMakeDLoc(dataRoot, firstBodyP, 0));
    caretManager.setCaret(firstBodyPLocation);

    // First 3 text characters in the 5th paragraph (at index 4).
    const pFiveStart = DLoc.mustMakeDLoc(dataRoot, ps[4].firstChild, 0);
    pFiveFirstThree = new DLocRange(
      caretManager.mustFromDataLocation(pFiveStart),
      caretManager.mustFromDataLocation(pFiveStart.makeWithOffset(3)));
    expect(pFiveFirstThree.mustMakeDOMRange().toString()).to.equal("abc");

    pFiveFirstFour = new DLocRange(
      caretManager.mustFromDataLocation(pFiveStart),
      caretManager.mustFromDataLocation(pFiveStart.makeWithOffset(4)));
    expect(pFiveFirstFour.mustMakeDOMRange().toString()).to.equal("abcd");

    const pSevenStart = DLoc.mustMakeDLoc(dataRoot, ps[6].firstChild, 0);
    pSevenFirstThree = new DLocRange(
      caretManager.mustFromDataLocation(pSevenStart),
      caretManager.mustFromDataLocation(pSevenStart.makeWithOffset(3)));
    expect(pSevenFirstThree.mustMakeDOMRange().toString()).to.equal("abc");

    // This is the first "abc" found when doing a TEXT search.
    firstABCText = new DLocRange(
      caretManager.mustFromDataLocation(ps[3].firstChild!.firstChild!, 0),
      caretManager.mustFromDataLocation(ps[3].lastChild!, 1));
  });
Example #4
0
  before(() => {
    guiRoot = editor.guiRoot;
    dataRoot = editor.dataRoot;
    caretManager = editor.caretManager;
    docScope = editor.caretManager.docDLocRange;

    ps = Array.from(editor.dataRoot.querySelectorAll("body p"));
    firstBodyP = ps[0];
    firstBodyPLocation = caretManager.mustFromDataLocation(
      DLoc.mustMakeDLoc(dataRoot, firstBodyP, 0));

    // First 3 text characters in the 5th paragraph (at index 4).
    const pFiveStart = DLoc.mustMakeDLoc(dataRoot, ps[4].firstChild, 0);
    pFiveFirstThree = new DLocRange(
      caretManager.mustFromDataLocation(pFiveStart),
      caretManager.mustFromDataLocation(pFiveStart.makeWithOffset(3)));
    expect(pFiveFirstThree.mustMakeDOMRange().toString()).to.equal("abc");

    pFiveFirstFour = new DLocRange(
      caretManager.mustFromDataLocation(pFiveStart),
      caretManager.mustFromDataLocation(pFiveStart.makeWithOffset(4)));
    expect(pFiveFirstFour.mustMakeDOMRange().toString()).to.equal("abcd");

    const pSevenStart = DLoc.mustMakeDLoc(dataRoot, ps[6].firstChild, 0);
    pSevenFirstThree = new DLocRange(
      caretManager.mustFromDataLocation(pSevenStart),
      caretManager.mustFromDataLocation(pSevenStart.makeWithOffset(3)));
    expect(pSevenFirstThree.mustMakeDOMRange().toString()).to.equal("abc");

    // This is the first "abc" found when doing a TEXT search.
    firstABCText = new DLocRange(
      caretManager.mustFromDataLocation(ps[3].firstChild!.firstChild!, 0),
      caretManager.mustFromDataLocation(ps[3].lastChild!, 1));

    // This is the first "abcd" found when doing a TEXT search.
    firstABCDText = new DLocRange(
      caretManager.mustFromDataLocation(ps[3].firstChild!.firstChild!, 0),
      caretManager.mustFromDataLocation(ps[3].lastChild!, 2));

    const rend = ps[7].getAttributeNode("rend")!;
    firstABCAttribute = new DLocRange(
      caretManager.mustFromDataLocation(rend, 0),
      caretManager.mustFromDataLocation(rend, 3));

    firstABCDAttribute = new DLocRange(
      caretManager.mustFromDataLocation(rend, 0),
      caretManager.mustFromDataLocation(rend, 4));

    secondABCAttribute = new DLocRange(
      caretManager.mustFromDataLocation(rend, 4),
      caretManager.mustFromDataLocation(rend, 7));
  });
Example #5
0
  function checkHighlightRanges(range: DLocRange): void {
    const highlights = document.querySelectorAll("._wed_highlight");
    expect(highlights).to.have.property("length").greaterThan(0);
    let highlightRect = highlights[0].getBoundingClientRect();
    const rangeRect =
      range.mustMakeDOMRange().getBoundingClientRect();

    // The highlights are built as a series of rectangles. Checking each and
    // every rectangle would be onerous. We check the start and end of the
    // range.

    // Rounding can make the boundaries vary a bit.
    expect(highlightRect).to.have.nested.property("top")
      .closeTo(rangeRect.top, 3);
    expect(highlightRect).to.have.nested.property("left")
      .closeTo(rangeRect.left, 3);

    highlightRect = highlights[highlights.length - 1].getBoundingClientRect();
    expect(highlightRect).to.have.nested.property("bottom")
      .closeTo(rangeRect.bottom, 3);
    expect(highlightRect).to.have.nested.property("right")
      .closeTo(rangeRect.right, 3);
  }
Example #6
0
 function isDocScope(x: DLocRange): boolean {
   return x.equals(docScope);
 }
Example #7
0
 function equalRanges(a: DLocRange, b: DLocRange): boolean {
   return a.equals(b);
 }
Example #8
0
 it("returns true if the location is between the ends", () => {
   assert.isTrue(range.contains(loc.makeWithOffset(1)));
 });
Example #9
0
 it("returns true if the location is at end of the range", () => {
   assert.isTrue(range.contains(loc.makeWithOffset(2)));
 });
Example #10
0
 it("returns false if the location is after the range", () => {
   assert.isFalse(range.contains(loc.makeWithOffset(3)));
 });