本文整理汇总了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);
});
};
示例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;
};
示例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));
};
示例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);
};
示例5:
const prependData = (target: Text, data: string): void => {
target.insertData(0, data);
};
示例6:
editor.undoManager.transact(() => {
firstTextNode.deleteData(0, pattern.start.length);
editor.execCommand(pattern.cmd, false, pattern.value);
});
示例7: insertBefore
const insertInline = (before: boolean, node: Node) => before ? insertBefore(node) : insertAfter(node);