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


TypeScript CaretWalker.CaretWalker函數代碼示例

本文整理匯總了TypeScript中tinymce/core/caret/CaretWalker.CaretWalker函數的典型用法代碼示例。如果您正苦於以下問題:TypeScript CaretWalker函數的具體用法?TypeScript CaretWalker怎麽用?TypeScript CaretWalker使用的例子?那麽, 這裏精選的函數代碼示例或許可以為您提供幫助。


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

示例1: CaretWalker

const getPositionsUntil = (predicate: CheckerPredicate, direction: HDirection, scope: HTMLElement, start: CaretPosition): LineInfo => {
  const caretWalker = CaretWalker(scope);
  let currentPos = start, nextPos: CaretPosition;
  const positions: CaretPosition[] = [];

  while (currentPos) {
    nextPos = walk(direction, caretWalker, currentPos);

    if (!nextPos) {
      break;
    }

    if (NodeType.isBr(nextPos.getNode(false))) {
      if (direction === HDirection.Forwards) {
        return { positions: flip(direction, positions).concat([nextPos]), breakType: BreakType.Br, breakAt: Option.some(nextPos) };
      } else {
        return { positions: flip(direction, positions), breakType: BreakType.Br, breakAt: Option.some(nextPos) };
      }
    }

    if (!nextPos.isVisible()) {
      currentPos = nextPos;
      continue;
    }

    if (predicate(currentPos, nextPos)) {
      const breakType = getBreakType(scope, direction, currentPos, nextPos);
      return { positions: flip(direction, positions), breakType, breakAt: Option.some(nextPos) };
    }

    positions.push(nextPos);
    currentPos = nextPos;
  }

  return { positions: flip(direction, positions), breakType: BreakType.Eol, breakAt: Option.none() };
};
開發者ID:danielpunkass,項目名稱:tinymce,代碼行數:36,代碼來源:LineReader.ts

示例2: ViewBlock

UnitTest.asynctest('browser.tinymce.core.CaretWalkerTest', (success, failure) => {
  const suite = LegacyUnit.createSuite();
  const viewBlock = ViewBlock();

  if (!Env.ceFalse) {
    return;
  }

  const getRoot = function () {
    return viewBlock.get();
  };

  const getChildNode = (childIndex: number) => {
    return getRoot().childNodes[childIndex];
  };

  const setupHtml = function (html) {
    viewBlock.update(html);
  };

  const findElm = function (selector) {
    return DomQuery(selector, getRoot())[0];
  };

  const findElmPos = function (selector, offset) {
    return CaretPosition(DomQuery(selector, getRoot())[0], offset);
  };

  const findTextPos = function (selector, offset) {
    return CaretPosition(DomQuery(selector, getRoot())[0].firstChild, offset);
  };

  const logicalCaret = CaretWalker(getRoot());

  suite.test('inside empty root', function () {
    setupHtml('');
    CaretAsserts.assertCaretPosition(logicalCaret.next(CaretPosition(getRoot(), 0)), null);
    CaretAsserts.assertCaretPosition(logicalCaret.prev(CaretPosition(getRoot(), 0)), null);
  });

  suite.test('on null', function () {
    setupHtml('');
    CaretAsserts.assertCaretPosition(logicalCaret.next(null), null);
    CaretAsserts.assertCaretPosition(logicalCaret.prev(null), null);
  });

  suite.test('within text node in root', function () {
    setupHtml('abc');
    CaretAsserts.assertCaretPosition(logicalCaret.next(CaretPosition(getRoot().firstChild, 0)), CaretPosition(getRoot().firstChild, 1));
    CaretAsserts.assertCaretPosition(logicalCaret.next(CaretPosition(getRoot().firstChild, 1)), CaretPosition(getRoot().firstChild, 2));
    CaretAsserts.assertCaretPosition(logicalCaret.next(CaretPosition(getRoot().firstChild, 2)), CaretPosition(getRoot().firstChild, 3));
    CaretAsserts.assertCaretPosition(logicalCaret.next(CaretPosition(getRoot().firstChild, 3)), null);
    CaretAsserts.assertCaretPosition(logicalCaret.prev(CaretPosition(getRoot().firstChild, 3)), CaretPosition(getRoot().firstChild, 2));
    CaretAsserts.assertCaretPosition(logicalCaret.prev(CaretPosition(getRoot().firstChild, 2)), CaretPosition(getRoot().firstChild, 1));
    CaretAsserts.assertCaretPosition(logicalCaret.prev(CaretPosition(getRoot().firstChild, 1)), CaretPosition(getRoot().firstChild, 0));
    CaretAsserts.assertCaretPosition(logicalCaret.prev(CaretPosition(getRoot().firstChild, 0)), null);
  });

  suite.test('within text node in element', function () {
    setupHtml('<p>abc</p>');
    CaretAsserts.assertCaretPosition(logicalCaret.next(findTextPos('p', 0)), findTextPos('p', 1));
    CaretAsserts.assertCaretPosition(logicalCaret.next(findTextPos('p', 1)), findTextPos('p', 2));
    CaretAsserts.assertCaretPosition(logicalCaret.next(findTextPos('p', 2)), findTextPos('p', 3));
    CaretAsserts.assertCaretPosition(logicalCaret.next(findTextPos('p', 3)), null);
    CaretAsserts.assertCaretPosition(logicalCaret.prev(findTextPos('p', 3)), findTextPos('p', 2));
    CaretAsserts.assertCaretPosition(logicalCaret.prev(findTextPos('p', 2)), findTextPos('p', 1));
    CaretAsserts.assertCaretPosition(logicalCaret.prev(findTextPos('p', 1)), findTextPos('p', 0));
    CaretAsserts.assertCaretPosition(logicalCaret.prev(findTextPos('p', 0)), null);
  });

  suite.test('from index text node over comment', function () {
    setupHtml('abcd<!-- x -->abcd');
    CaretAsserts.assertCaretPosition(logicalCaret.next(CaretPosition(getRoot(), 0)), CaretPosition(getRoot().firstChild, 0));
    CaretAsserts.assertCaretPosition(logicalCaret.next(CaretPosition(getRoot(), 1)), CaretPosition(getRoot().lastChild, 0));
    CaretAsserts.assertCaretPosition(logicalCaret.prev(CaretPosition(getRoot(), 2)), CaretPosition(getRoot().firstChild, 4));
    CaretAsserts.assertCaretPosition(logicalCaret.prev(CaretPosition(getRoot(), 3)), CaretPosition(getRoot().lastChild, 4));
  });

  suite.test('from text to text across elements', function () {
    setupHtml('<p>abc</p><p>abc</p>');
    CaretAsserts.assertCaretPosition(logicalCaret.next(findTextPos('p:first', 3)), findTextPos('p:last', 0));
    CaretAsserts.assertCaretPosition(logicalCaret.prev(findTextPos('p:last', 0)), findTextPos('p:first', 3));
  });

  suite.test('from text to text across elements with siblings', function () {
    setupHtml('<p>abc<b><!-- x --></b></p><p><b><!-- x --></b></p><p><b><!-- x --></b>abc</p>');
    CaretAsserts.assertCaretPosition(logicalCaret.next(findTextPos('p:first', 3)), CaretPosition(findElm('p:last').lastChild, 0));
    CaretAsserts.assertCaretPosition(logicalCaret.prev(CaretPosition(findElm('p:last').lastChild, 0)), findTextPos('p:first', 3));
  });

  suite.test('from input to text', function () {
    setupHtml('123<input>456');
    CaretAsserts.assertCaretPosition(logicalCaret.next(CaretPosition(getRoot(), 2)), CaretPosition(getRoot().lastChild, 0));
    CaretAsserts.assertCaretPosition(logicalCaret.prev(CaretPosition(getRoot(), 1)), CaretPosition(getRoot().firstChild, 3));
  });

  suite.test('from input to input across elements', function () {
    setupHtml('<p><input></p><p><input></p>');
    CaretAsserts.assertCaretPosition(logicalCaret.next(CaretPosition(findElm('p:first'), 1)), CaretPosition(findElm('p:last'), 0));
    CaretAsserts.assertCaretPosition(logicalCaret.prev(CaretPosition(findElm('p:last'), 0)), CaretPosition(findElm('p:first'), 1));
//.........這裏部分代碼省略.........
開發者ID:mdgbayly,項目名稱:tinymce,代碼行數:101,代碼來源:CaretWalkerTest.ts


注:本文中的tinymce/core/caret/CaretWalker.CaretWalker函數示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。