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


TypeScript TreeWalker.next函数代码示例

本文整理汇总了TypeScript中tinymce/core/api/dom/TreeWalker.next函数的典型用法代码示例。如果您正苦于以下问题:TypeScript next函数的具体用法?TypeScript next怎么用?TypeScript next使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。


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

示例1: TreeWalker

const findBlockPattern = (dom: DOMUtils, patterns: BlockPattern[], rng: Range): Option<BlockPattern> => {
  const block = dom.getParent(rng.startContainer, dom.isBlock);

  if (!(dom.is(block, 'p') && isElement(block))) {
    return Option.none();
  }
  const walker = new TreeWalker(block, block);
  let node: Node;
  let firstTextNode: Text;
  while ((node = walker.next())) {
    if (isText(node)) {
      firstTextNode = node;
      break;
    }
  }
  if (!firstTextNode) {
    return Option.none();
  }
  const pattern = findPattern(patterns, firstTextNode.data);
  if (!pattern) {
    return Option.none();
  }
  if (Tools.trim(block.textContent).length === pattern.start.length) {
    return Option.none();
  }
  return Option.some(pattern);
};
开发者ID:tinymce,项目名称:tinymce,代码行数:27,代码来源:FindPatterns.ts

示例2: function

const applyBlockFormat = function (editor, patterns) {
  let selection, dom, container, firstTextNode, node, format, textBlockElm, pattern, walker, rng, offset;

  selection = editor.selection;
  dom = editor.dom;

  if (!selection.isCollapsed()) {
    return;
  }

  textBlockElm = dom.getParent(selection.getStart(), 'p');
  if (textBlockElm) {
    walker = new TreeWalker(textBlockElm, textBlockElm);
    while ((node = walker.next())) {
      if (node.nodeType === 3) {
        firstTextNode = node;
        break;
      }
    }

    if (firstTextNode) {
      pattern = Patterns.findPattern(patterns, firstTextNode.data);
      if (!pattern) {
        return;
      }

      rng = selection.getRng(true);
      container = rng.startContainer;
      offset = rng.startOffset;

      if (firstTextNode === container) {
        offset = Math.max(0, offset - pattern.start.length);
      }

      if (Tools.trim(firstTextNode.data).length === pattern.start.length) {
        return;
      }

      if (pattern.format) {
        format = editor.formatter.get(pattern.format);
        if (format && format[0].block) {
          firstTextNode.deleteData(0, pattern.start.length);
          editor.formatter.apply(pattern.format, {}, firstTextNode);

          rng.setStart(container, offset);
          rng.collapse(true);
          selection.setRng(rng);
        }
      }

      if (pattern.cmd) {
        editor.undoManager.transact(function () {
          firstTextNode.deleteData(0, pattern.start.length);
          editor.execCommand(pattern.cmd);
        });
      }
    }
  }
};
开发者ID:abstask,项目名称:tinymce,代码行数:59,代码来源:Formatter.ts

示例3: function

  suite.test('next', function () {
    const walker = new TreeWalker(nodes[0], viewBlock.get());
    let actualNodes;

    actualNodes = [walker.current()];
    while ((walker.next())) {
      actualNodes.push(walker.current());
    }

    LegacyUnit.equal(compareNodeLists(nodes, actualNodes), true, 'Should be the same');
  });
开发者ID:abstask,项目名称:tinymce,代码行数:11,代码来源:TreeWalkerTest.ts

示例4: TreeWalker

const isCollapsed = (start: Node, end: Node, root: HTMLElement) => {
  const walker = new TreeWalker(start, root);
  while (walker.next()) {
    const node = walker.current();
    if (isText(node) && node.data.length === 0) {
      continue;
    }
    return node === end;
  }
  return false;
};
开发者ID:tinymce,项目名称:tinymce,代码行数:11,代码来源:PatternApplication.ts

示例5: function

const getSelectedElements = function (rootElm, startNode, endNode) {
  let walker, node;
  const elms = [];

  walker = new TreeWalker(startNode, rootElm);
  for (node = startNode; node; node = walker.next()) {
    if (node.nodeType === 1) {
      elms.push(node);
    }

    if (node === endNode) {
      break;
    }
  }

  return elms;
};
开发者ID:,项目名称:,代码行数:17,代码来源:

示例6: TreeWalker

const getText = (node: Node, schema: Schema): string => {
  const blockElements: SchemaMap = schema.getBlockElements();
  const shortEndedElements: SchemaMap = schema.getShortEndedElements();
  const whiteSpaceElements = schema.getWhiteSpaceElements();
  const isSeparator = (node: Node) => (
    blockElements[node.nodeName] || shortEndedElements[node.nodeName] || whiteSpaceElements[node.nodeName]
  );

  let txt = '';
  const treeWalker = new TreeWalker(node, node);
  while ((node = treeWalker.next())) {
    if (node.nodeType === 3) {
      txt += (node as CharacterData).data;
    } else if (txt.length !== 0 && isSeparator(node)) {
      txt += ' ';
    }
  }

  return txt;
};
开发者ID:tinymce,项目名称:tinymce,代码行数:20,代码来源:WordCount.ts

示例7: function

const findNextCaretContainer = function (editor, rng, isForward, root) {
  let node = rng.startContainer;
  const offset = rng.startOffset;
  let nonEmptyBlocks, walker;

  if (node.nodeType === 3 && (isForward ? offset < node.data.length : offset > 0)) {
    return node;
  }

  nonEmptyBlocks = editor.schema.getNonEmptyElements();
  if (node.nodeType === 1) {
    node = RangeUtils.getNode(node, offset);
  }

  walker = new TreeWalker(node, root);

  // Delete at <li>|<br></li> then jump over the bogus br
  if (isForward) {
    if (NodeType.isBogusBr(editor.dom, node)) {
      walker.next();
    }
  }

  while ((node = walker[isForward ? 'next' : 'prev2']())) {
    if (node.nodeName === 'LI' && !node.hasChildNodes()) {
      return node;
    }

    if (nonEmptyBlocks[node.nodeName]) {
      return node;
    }

    if (node.nodeType === 3 && node.data.length > 0) {
      return node;
    }
  }
};
开发者ID:danielpunkass,项目名称:tinymce,代码行数:37,代码来源:Delete.ts


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