当前位置: 首页>>代码示例>>TypeScript>>正文


TypeScript CaretManager.setRange方法代码示例

本文整理汇总了TypeScript中wed/caret-manager.CaretManager.setRange方法的典型用法代码示例。如果您正苦于以下问题:TypeScript CaretManager.setRange方法的具体用法?TypeScript CaretManager.setRange怎么用?TypeScript CaretManager.setRange使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在wed/caret-manager.CaretManager的用法示例。


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

示例1: it

  it("wraps elements in elements (no limit case)", () => {
    const initial = editor.dataRoot.querySelectorAll("body>p")[4];

    // Make sure we are looking at the right thing.
    assert.equal(initial.childNodes.length, 1);
    assert.equal(initial.firstChild!.textContent, "abcdefghij");

    const trs = editor.modeTree.getMode(initial)
      .getContextualActions(["wrap"], "hi", initial, 0);

    let caret = caretManager.fromDataLocation(initial.firstChild!, 3)!;
    caretManager.setRange(caret, caret.makeWithOffset(caret.offset + 2));

    trs[0].execute({ node: undefined, name: "hi" });

    assert.equal(initial.childNodes.length, 3, "length after first wrap");
    assert.equal(
      initial.outerHTML,
      `<p xmlns="http://www.tei-c.org/ns/1.0">abc<hi>de</hi>fghij</p>`);

    caret = caretManager.fromDataLocation(initial.firstChild!, 2)!;
    caretManager.setRange(
      caret,
      caretManager.fromDataLocation(initial.lastChild!, 2)!);

    trs[0].execute({ node: undefined, name: "hi" });

    assert.equal(initial.childNodes.length, 3, "length after second wrap");
    assert.equal(initial.outerHTML,
                 `<p xmlns="http://www.tei-c.org/ns/1.0">ab<hi>c<hi>de</hi>fg\
</hi>hij</p>`);
  });
开发者ID:lddubeau,项目名称:wed,代码行数:32,代码来源:wed-transformation-test.ts

示例2: it

  it("prevents cutting from readonly elements", async () => {
    const initial = editor.dataRoot.querySelector("bar")!;
    const initialGUI =
      caretManager.fromDataLocation(initial, 0)!.node as Element;
    assert.isTrue(initialGUI.classList.contains("_readonly"));
    const initialValue = initial.textContent!;

    const guiStart = caretManager.fromDataLocation(initial.firstChild!, 1)!;
    caretManager.setCaret(guiStart);
    caretManager.setRange(
      guiStart,
      caretManager.fromDataLocation(initial.firstChild!, 2)!);

    // Synthetic event
    editor.$guiRoot.trigger(new $.Event("cut"));
    await delay(1);

    assert.equal(initial.textContent, initialValue);
    // Try again, after removing _readonly so that we prove the only reason the
    // cut did not work is that _readonly was present.
    initialGUI.classList.remove("_readonly");
    editor.$guiRoot.trigger(new $.Event("cut"));

    await delay(1);
    assert.equal(initial.textContent,
                 initialValue.slice(0, 1) + initialValue.slice(2));
  });
开发者ID:lddubeau,项目名称:wed,代码行数:27,代码来源:wed-wildcard-test.ts

示例3: it

  it("handles cutting a bad selection", (done) => {
    const p = editor.dataRoot.querySelector("body>p")!;
    const originalInnerHtml = p.innerHTML;
    // Start caret is inside the term element.
    const guiStart =
      caretManager.fromDataLocation(p.childNodes[1].firstChild!, 1)!;
    const guiEnd = caretManager.fromDataLocation(p.childNodes[2], 5)!;
    caretManager.setRange(guiStart, guiEnd);

    assert.equal(p.innerHTML, originalInnerHtml);
    const straddlingModal = editor.modals.getModal("straddling");
    const $top = straddlingModal.getTopLevel();
    $top.one("shown.bs.modal", () => {
      // Wait until visible to add this handler so that it is run after the
      // callback that wed sets on the modal.
      $top.one("hidden.bs.modal", () => {
        assert.equal(p.innerHTML, originalInnerHtml);
        caretCheck(editor, guiEnd.node, guiEnd.offset, "final position");
        done();
      });
    });
    // Synthetic event
    const event = new $.Event("cut");
    editor.$guiRoot.trigger(event);
    // This clicks dismisses the modal
    straddlingModal.getTopLevel().find(".btn-primary")[0].click();
  });
开发者ID:lddubeau,项目名称:wed,代码行数:27,代码来源:wed-paste-copy-cut-test.ts

示例4: it

 it("starts with start === selection start", () => {
   caretManager.setRange(pFiveFirstThree.start.node,
                         pFiveFirstThree.start.offset,
                         pFiveFirstThree.end.node,
                         pFiveFirstThree.end.offset);
   expect(makeSr()).to.have.nested.property("search.start")
     .satisfy((x: DLoc) => x.equals(pFiveFirstThree.start));
 });
开发者ID:lddubeau,项目名称:wed,代码行数:8,代码来源:search-replace-test.ts


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