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


TypeScript CaretManager.getNormalizedCaret方法代码示例

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


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

示例1: it

  it("unwraps elements", () => {
    const initial = editor.dataRoot.getElementsByTagName("title")[0];

    // Make sure we are looking at the right thing.
    assert.equal(initial.childNodes.length, 1);
    assert.equal(initial.firstChild!.textContent, "abcd");
    caretManager.setCaret(initial, 0);
    let caret = caretManager.getNormalizedCaret()!;
    assert.equal(caret.node.childNodes[caret.offset].nodeValue, "abcd");

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

    caretManager.setCaret(initial.firstChild, 1);
    caret = caretManager.getNormalizedCaret()!;
    caretManager.setRange(caret, caret.makeWithOffset(caret.offset + 2));

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

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

    trs[0].execute({ node, element_name: "hi" });
    assert.equal(initial.childNodes.length, 1, "length after unwrap");
    assert.equal(initial.firstChild!.textContent, "abcd");
  });
开发者ID:lddubeau,项目名称:wed,代码行数:27,代码来源:wed-transformation-test.ts

示例2: it

    it("when there is no caret", async () => {
      const initial = guiRoot.getElementsByClassName("title")[0].childNodes[1];
      assert.isUndefined(caretManager.getNormalizedCaret());
      activateContextMenu(editor, initial.parentNode as Element);

      await delay(1);
      // tslint:disable-next-line:no-any
      assert.isDefined((menuManager as any).currentDropdown,
                       "dropdown defined");
      assert.isDefined(caretManager.getNormalizedCaret(), "caret defined");
    });
开发者ID:lddubeau,项目名称:wed,代码行数:11,代码来源:wed-menu-test.ts

示例3: async

 "outside wed", async () => {
   caretManager.clearSelection(); // Also clears the caret.
   assert.isUndefined(caretManager.getNormalizedCaret());
   activateContextMenu(editor,
                       guiRoot.getElementsByClassName("title")[0]);
   await delay(1);
   // tslint:disable-next-line:no-any
   assert.isDefined((menuManager as any).currentDropdown);
 });
开发者ID:lddubeau,项目名称:wed,代码行数:9,代码来源:wed-menu-test.ts

示例4: it

  it("element becoming empty acquires a placeholder", () => {
    // Text node inside title.
    const initial = editor.dataRoot.getElementsByTagName("title")[0];

    // Make sure we are looking at the right thing.
    assert.equal(initial.childNodes.length, 1);
    assert.equal(initial.firstChild!.textContent, "abcd");
    caretManager.setCaret(initial, 0);
    const caret = caretManager.getNormalizedCaret()!;
    assert.equal(caret.node.childNodes[caret.offset].nodeValue, "abcd");

    // Delete all contents.
    editor.dataUpdater.removeNode(initial.firstChild);

    // We should have a placeholder now, between the two labels.
    assert.equal(caret.node.childNodes.length, 3);
    assert.isTrue((caret.node.childNodes[1] as Element).classList.contains(
      "_placeholder"));
  });
开发者ID:lddubeau,项目名称:wed,代码行数:19,代码来源:wed-decoration-test.ts

示例5: it

  it("clicking a phantom element after typing text works", (done) => {
    // We create a special phantom element because the generic mode does not
    // create any.
    const title = editor.guiRoot.getElementsByClassName("title")[0];
    const phantom = title.ownerDocument.createElement("span");
    phantom.className = "_phantom";
    phantom.textContent = "phantom";
    title.insertBefore(phantom, null);

    // Text node inside paragraph.
    const initial = editor.dataRoot.querySelector("body>p")!;
    caretManager.setCaret(initial.firstChild, 1);

    editor.type(" ");
    assert.equal(initial.firstChild!.nodeValue, "B lah blah ");

    const caret = caretManager.getNormalizedCaret()!;

    // We're simulating how Chrome would handle it. When a mousedown event
    // occurs, Chrome moves the caret *after* the mousedown event is processed.
    const event = new $.Event("mousedown");
    event.target = phantom;
    caretManager.setCaret(caret);

    // This simulates the movement of the caret after the mousedown event is
    // processed. This will be processed after the mousedown handler but before
    // _seekCaret is run.
    window.setTimeout(() => {
      caretManager.setCaret(phantom, 0);
    }, 0);

    // We trigger the event here so that the order specified above is respected.
    $(phantom).trigger(event);

    window.setTimeout(() => {
      const clickEvent = new $.Event("click");
      clickEvent.target = phantom;
      $(phantom).trigger(clickEvent);
      done();
    }, 1);
  });
开发者ID:lddubeau,项目名称:wed,代码行数:41,代码来源:wed-typing-test.ts

示例6: it

 it("works even if there is no caret defined", () => {
   editor.caretManager.onBlur();
   assert.equal(caretManager.getNormalizedCaret(), undefined, "no caret");
   caretManager.move("right");
   assert.equal(caretManager.getNormalizedCaret(), undefined, "no caret");
 });
开发者ID:lddubeau,项目名称:wed,代码行数:6,代码来源:wed-caret-test.ts


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