本文整理匯總了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);