本文整理汇总了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;
};