當前位置: 首頁>>代碼示例>>TypeScript>>正文


TypeScript DLoc.makeRange方法代碼示例

本文整理匯總了TypeScript中wed/dloc.DLoc.makeRange方法的典型用法代碼示例。如果您正苦於以下問題:TypeScript DLoc.makeRange方法的具體用法?TypeScript DLoc.makeRange怎麽用?TypeScript DLoc.makeRange使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在wed/dloc.DLoc的用法示例。


在下文中一共展示了DLoc.makeRange方法的1個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的TypeScript代碼示例。

示例1: 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.makeRange方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。