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


TypeScript dom-globals.Text类代码示例

本文整理汇总了TypeScript中@ephox/dom-globals.Text的典型用法代码示例。如果您正苦于以下问题:TypeScript Text类的具体用法?TypeScript Text怎么用?TypeScript Text使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


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

示例1:

const applyReplacement = (editor: Editor, target: Text, match: ReplacementMatch) => {
  target.deleteData(match.startOffset, match.pattern.start.length);
  editor.insertContent(match.pattern.replacement);

  Option.from(target.nextSibling).filter(isText).each((nextSibling: Text) => {
    nextSibling.insertData(0, target.data);
    editor.dom.remove(target);
  });
};
开发者ID:danielpunkass,项目名称:tinymce,代码行数:9,代码来源:PatternApplication.ts

示例2: normalizeWhitespaceAfter

const mergeTextNodes = (prevNode: Text, nextNode: Text, normalizeWhitespace?: boolean): Text => {
  const whitespaceOffset = Strings.rTrim(prevNode.data).length;
  // Merge the elements
  prevNode.appendData(nextNode.data);
  Remove.remove(Element.fromDom(nextNode));

  // Normalize the whitespace around the merged elements, to ensure it doesn't get lost
  if (normalizeWhitespace) {
    normalizeWhitespaceAfter(prevNode, whitespaceOffset);
  }

  return prevNode;
};
开发者ID:danielpunkass,项目名称:tinymce,代码行数:13,代码来源:MergeText.ts

示例3: normalizeContent

const normalize = (node: Text, offset: number, count: number) => {
  if (count === 0) {
    return;
  }

  // Get the whitespace
  const whitespace = node.data.slice(offset, offset + count);

  // Determine if we're at the end of start of the content
  const isEndOfContent = offset + count >= node.data.length;
  const isStartOfContent = offset === 0;

  // Replace the original whitespace with the normalized whitespace content
  node.replaceData(offset, count, normalizeContent(whitespace, isStartOfContent, isEndOfContent));
};
开发者ID:danielpunkass,项目名称:tinymce,代码行数:15,代码来源:MergeText.ts

示例4: TreeWalker

const applyBlockPattern = (editor: Editor, pattern: BlockPattern) => {
  const dom = editor.dom;
  const rng = editor.selection.getRng();
  const block = dom.getParent(rng.startContainer, dom.isBlock);
  if (!block || !dom.is(block, 'p') || !isElement(block)) {
    return;
  }

  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;
  }
  if (!Strings.startsWith(firstTextNode.data, pattern.start)) {
    return;
  }
  if (Tools.trim(block.textContent).length === pattern.start.length) {
    return;
  }

  // add a marker to store the cursor position
  const cursor = editor.selection.getBookmark();
  if (pattern.type === 'block-format') {
    if (isBlockFormatName(pattern.format, editor.formatter)) {
      editor.undoManager.transact(() => {
        firstTextNode.deleteData(0, pattern.start.length);
        editor.formatter.apply(pattern.format);
      });
    }
  } else if (pattern.type === 'block-command') {
    editor.undoManager.transact(() => {
      firstTextNode.deleteData(0, pattern.start.length);
      editor.execCommand(pattern.cmd, false, pattern.value);
    });
  }
  // return the selection
  editor.selection.moveToBookmark(cursor);
};
开发者ID:tinymce,项目名称:tinymce,代码行数:45,代码来源:PatternApplication.ts

示例5:

const prependData = (target: Text, data: string): void => {
  target.insertData(0, data);
};
开发者ID:tinymce,项目名称:tinymce,代码行数:3,代码来源:SetSelectionContent.ts

示例6:

 editor.undoManager.transact(() => {
   firstTextNode.deleteData(0, pattern.start.length);
   editor.execCommand(pattern.cmd, false, pattern.value);
 });
开发者ID:tinymce,项目名称:tinymce,代码行数:4,代码来源:PatternApplication.ts

示例7: insertBefore

const insertInline = (before: boolean, node: Node) => before ? insertBefore(node) : insertAfter(node);
开发者ID:danielpunkass,项目名称:tinymce,代码行数:1,代码来源:CaretContainerInline.ts


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