本文整理匯總了TypeScript中@ephox/dom-globals.Range.deleteContents方法的典型用法代碼示例。如果您正苦於以下問題:TypeScript Range.deleteContents方法的具體用法?TypeScript Range.deleteContents怎麽用?TypeScript Range.deleteContents使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類@ephox/dom-globals.Range
的用法示例。
在下文中一共展示了Range.deleteContents方法的2個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的TypeScript代碼示例。
示例1: prependData
const rngSetContent = (rng: Range, fragment: DocumentFragment): void => {
const firstChild = Option.from(fragment.firstChild).map(Element.fromDom);
const lastChild = Option.from(fragment.lastChild).map(Element.fromDom);
rng.deleteContents();
rng.insertNode(fragment);
const prevText = firstChild.bind(Traverse.prevSibling).filter(Node.isText).bind(removeEmpty);
const nextText = lastChild.bind(Traverse.nextSibling).filter(Node.isText).bind(removeEmpty);
// Join start
Options.liftN([prevText, firstChild.filter(Node.isText)], (prev: Element, start: Element) => {
prependData(start.dom(), prev.dom().data);
Remove.remove(prev);
});
// Join end
Options.liftN([nextText, lastChild.filter(Node.isText)], (next: Element, end: Element) => {
const oldLength = end.dom().length;
end.dom().appendData(next.dom().data);
rng.setEnd(end.dom(), oldLength);
Remove.remove(next);
});
rng.collapse(false);
};
示例2: trimEmptyTextNode
const deleteContentAndShowCaret = (editor: Editor, range: Range, node: Node, direction: HDirection, forward: boolean, peekCaretPosition: CaretPosition) => {
const caretRange = CefUtils.showCaret(direction, editor, peekCaretPosition.getNode(!forward) as Element, forward, true);
// Delete the selected content
if (range.collapsed) {
const deleteRange = range.cloneRange();
if (forward) {
deleteRange.setEnd(caretRange.startContainer, caretRange.startOffset);
} else {
deleteRange.setStart(caretRange.endContainer, caretRange.endOffset);
}
deleteRange.deleteContents();
} else {
range.deleteContents();
}
editor.selection.setRng(caretRange);
trimEmptyTextNode(editor.dom, node);
return true;
};