當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。