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


TypeScript CaretManager.setCaret方法代码示例

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


在下文中一共展示了CaretManager.setCaret方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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("moving the caret scrolls the pane", (done) => {
    const initial = editor.dataRoot;
    caretManager.setCaret(initial.firstChild, 0);

    // tslint:disable-next-line:no-any
    const scroller = (editor as any).scroller;

    const initialScroll = scroller.scrollTop;

    scroller.events.pipe(first()).subscribe(() => {
      // We need to wait until the scroller has fired the scroll event.
      assert.isTrue(initialScroll < scroller.scrollTop);
      const caretRect = editor.caretManager.mark.getBoundingClientRect();
      const scrollerRect = scroller.getBoundingClientRect();
      assert.equal(distFromRect(caretRect.left, caretRect.top,
                                scrollerRect.left, scrollerRect.top,
                                scrollerRect.right,
                                scrollerRect.bottom),
                   0, "caret should be in visible space");
      done();
    });

    caretManager.setCaret(initial.firstChild,
                          initial.firstChild!.childNodes.length);
  });
开发者ID:lddubeau,项目名称:wed,代码行数:25,代码来源:wed-caret-test.ts

示例3: it

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

    // Synthetic event
    let event = makeFakePasteEvent({
      types: ["text/plain"],
      getData: () => "a",
    });
    editor.$guiRoot.trigger(event);
    assert.equal(initial.textContent, initialValue);
    dataCaretCheck(editor, initial, 0, "final position");

    // Check that removing _readonly would make the paste work. This proves that
    // the only thing that was preventing pasting was _readonly.
    initialGUI.classList.remove("_readonly");
    caretManager.setCaret(initial, 0);

    // We have to create a new event.
    event = makeFakePasteEvent({
      types: ["text/plain"],
      getData: () => "a",
    });

    editor.$guiRoot.trigger(event);
    assert.equal(initial.textContent, `a${initialValue}`);
    dataCaretCheck(editor, initial.firstChild!, 1, "final position");
  });
开发者ID:lddubeau,项目名称:wed,代码行数:32,代码来源:wed-wildcard-test.ts

示例4: it

  it("typing multiple spaces in an attribute normalizes the space", () => {
    // Text node inside title.
    let initial = getAttributeValuesFor(ps[7])[0].firstChild as Text;
    caretManager.setCaret(initial, 0);
    assert.equal(initial.data, "rend_value");

    editor.type(" ");

    // We have to refetch because the decorations have been redone.
    initial = getAttributeValuesFor(ps[7])[0].firstChild as Text;
    assert.equal(initial.data, " rend_value");
    caretCheck(editor, initial, 1, "caret after text insertion");

    // Check that the data is also modified
    const dataNode = editor.toDataNode(initial) as Attr;
    assert.equal(dataNode.value, " rend_value");

    editor.type(" ");

    // We have to refetch because the decorations have been redone.
    initial = getAttributeValuesFor(ps[7])[0].firstChild as Text;
    assert.equal(initial.data, " rend_value");
    caretCheck(editor, initial, 1, "caret after text insertion");

    // Check that the data is also modified
    assert.equal(dataNode.value, " rend_value");

    caretManager.setCaret(initial, 11);

    editor.type(" ");

    // We have to refetch because the decorations have been redone.
    initial = getAttributeValuesFor(ps[7])[0].firstChild as Text;
    assert.equal(initial.data, " rend_value ");
    caretCheck(editor, initial, 12, "caret after text insertion");

    // Check that the data is also modified
    assert.equal(dataNode.value, " rend_value ");

    editor.type(" ");

    // We have to refetch because the decorations have been redone.
    initial = getAttributeValuesFor(ps[7])[0].firstChild as Text;
    assert.equal(initial.data, " rend_value ");
    caretCheck(editor, initial, 12, "caret after text insertion");

    // Check that the data is also modified
    assert.equal(dataNode.value, " rend_value ");
  });
开发者ID:lddubeau,项目名称:wed,代码行数:49,代码来源:wed-typing-test.ts

示例5: it

 it("for which the mode provides completion", () => {
   const p = ps[13];
   const attrVals = getAttributeValuesFor(p);
   caretManager.setCaret(attrVals[0].firstChild, 0);
   // This is an arbitrary menu item we check for.
   contextMenuHasOption(editor, /^completion1$/);
 });
开发者ID:lddubeau,项目名称:wed,代码行数:7,代码来源:wed-menu-test.ts

示例6: 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

示例7: it

  it("undoing an attribute value change undoes the value change", () => {
    let initial = getAttributeValuesFor(ps[7])[0].firstChild as Text;
    caretManager.setCaret(initial, 4);
    assert.equal(initial.data, "rend_value", "initial value");
    editor.type("blah");

    // We have to refetch because the decorations have been redone.
    initial = getAttributeValuesFor(ps[7])[0].firstChild as Text;
    assert.equal(initial.data, "rendblah_value");
    caretCheck(editor, initial, 8, "caret after text insertion");

    // Check that the data is also modified
    const dataNode = editor.toDataNode(initial) as Attr;
    assert.equal(dataNode.value, "rendblah_value");

    editor.undo();

    // We have to refetch because the decorations have been redone.
    initial = getAttributeValuesFor(ps[7])[0].firstChild as Text;
    assert.equal(initial.data, "rend_value");
    caretCheck(editor, initial, 4, "caret after undo");

    // Check that the data change has been undone.
    assert.equal(dataNode.value, "rend_value", "value undone");
  });
开发者ID:lddubeau,项目名称:wed,代码行数:25,代码来源:wed-undo-redo-test.ts

示例8: it

  it("pasting structured text: invalid, decline pasting as text", (done) => {
    const p = editor.dataRoot.querySelector("body>p")!;
    const initial = p.firstChild!;
    caretManager.setCaret(initial, 0);
    const initialValue = p.innerHTML;

    // Synthetic event
    const event = makeFakePasteEvent({
      types: ["text/html", "text/plain"],
      getData: () => p.outerHTML,
    });
    const pasteModal = editor.modals.getModal("paste");
    const $top = pasteModal.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, initialValue);
        dataCaretCheck(editor, initial, 0, "final position");
        done();
      });
    });
    editor.$guiRoot.trigger(event);
    // This clicks "No".
    pasteModal.getTopLevel().find(".modal-footer .btn")[1].click();
  });
开发者ID:lddubeau,项目名称:wed,代码行数:26,代码来源:wed-paste-copy-cut-test.ts


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