• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

TypeScript dloc.DLoc类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了TypeScript中wed/dloc.DLoc的典型用法代码示例。如果您正苦于以下问题:TypeScript DLoc类的具体用法?TypeScript DLoc怎么用?TypeScript DLoc使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。



在下文中一共展示了DLoc类的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的TypeScript代码示例。

示例1: describe

      describe("(parent - child positions)", () => {
        let parentBefore: DLoc;
        let parentAfter: DLoc;

        before(() => {
          parentBefore = DLoc.mustMakeDLoc(root, p.parentNode, 0);
          parentAfter = parentBefore.makeWithOffset(1);
          // We want to check that we are looking at the p element we think
          // we are looking at.
          assert.equal(parentBefore.node.childNodes[0], p);
        });

        it("returns -1 if this is a parent position before other", () => {
          assert.equal(parentBefore.compare(loc), -1);
        });

        it("returns 1 if this is a parent position after other", () => {
          assert.equal(parentAfter.compare(loc), 1);
        });

        it("returns 1 if this is a child position after other", () => {
          assert.equal(loc.compare(parentBefore), 1);
        });

        it("returns -1 if this is a child position before other", () => {
          assert.equal(loc.compare(parentAfter), -1);
        });
      });
开发者ID:lddubeau,项目名称:wed,代码行数:28,代码来源:dloc-test.ts


示例2: beforeEach

  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));
  });
开发者ID:lddubeau,项目名称:wed,代码行数:33,代码来源:quick-search-test.ts


示例3: before

 before(() => {
   parentBefore = DLoc.mustMakeDLoc(root, p.parentNode, 0);
   parentAfter = parentBefore.makeWithOffset(1);
   // We want to check that we are looking at the p element we think
   // we are looking at.
   assert.equal(parentBefore.node.childNodes[0], p);
 });
开发者ID:lddubeau,项目名称:wed,代码行数:7,代码来源:dloc-test.ts


示例4: it

 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));
 });
开发者ID:lddubeau,项目名称:wed,代码行数:8,代码来源:dloc-test.ts


示例5: before

  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));
  });
开发者ID:lddubeau,项目名称:wed,代码行数:52,代码来源:search-test.ts


示例6: itNoIE

  itNoIE("proper caret position for elements that span lines", () => {
    const p = editor.dataRoot.querySelectorAll("body>p")[5];

    // Check that we are testing what we want to test. The end label for the hi
    // element must be on the next line. If we don't have that condition yet,
    // we modify the document to create the condition we want.
    let textLoc: DLoc;
    let hi: Element;
    // This is extremely high on purpose. We don't want to have an arbitrarily
    // low number that will cause issues *sometimes*.
    let tries = 1000;
    let satisfied = false;
    // tslint:disable-next-line:no-constant-condition
    while (true) {
      tries--;
      textLoc = caretManager.fromDataLocation(p.lastChild!, 2)!;
      assert.equal(textLoc.node.nodeType, Node.TEXT_NODE);
      const his =
        (textLoc.node.parentNode as Element).getElementsByClassName("hi");
      hi = his[his.length - 1];
      const startRect = firstGUI(hi)!.getBoundingClientRect();
      const endRect = lastGUI(hi)!.getBoundingClientRect();
      if (endRect.top > startRect.top + startRect.height) {
        satisfied = true;
        break;
      }
      if (tries === 0) {
        break;
      }
      editor.dataUpdater.insertText(editor.toDataNode(hi)!, 0, "AA");
    }

    assert.isTrue(satisfied,
                  "PRECONDITION FAILED: the test is unable to establish the \
necessary precondition");

    hi.scrollIntoView(true);
    const event = new $.Event("mousedown");
    event.target = textLoc.node.parentNode as Element;
    const { range } = textLoc.makeRange(textLoc.make(textLoc.node, 3))!;
    const { top, bottom, left } = range.getBoundingClientRect();
    event.clientX = left;
    event.clientY = (top + bottom) / 2;
    event.pageX = event.clientX + editor.window.document.body.scrollLeft;
    event.pageY = event.clientY + editor.window.document.body.scrollTop;
    event.which = 1; // First mouse button.
    editor.$guiRoot.trigger(event);
    caretCheck(editor, textLoc.node, textLoc.offset,
               "the caret should be in the text node");
  });
开发者ID:lddubeau,项目名称:wed,代码行数:50,代码来源:wed-caret-test.ts



注:本文中的wed/dloc.DLoc类示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
TypeScript dloc.DLoc.makeDLoc类代码示例发布时间:2022-05-25
下一篇:
TypeScript caret-manager.CaretManager类代码示例发布时间:2022-05-25
热门推荐
热门话题
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap