本文整理匯總了TypeScript中prosemirror-model.Node.resolve方法的典型用法代碼示例。如果您正苦於以下問題:TypeScript Node.resolve方法的具體用法?TypeScript Node.resolve怎麽用?TypeScript Node.resolve使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類prosemirror-model.Node
的用法示例。
在下文中一共展示了Node.resolve方法的1個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的TypeScript代碼示例。
示例1: selectAroundMark
selectAroundMark(markType: MarkType, doc: Node, pos: number, dispatchTransaction): Mark {
let $pos = doc.resolve(pos),
parent = $pos.parent;
let start = parent.childAfter($pos.parentOffset);
if (!start.node || start.node.marks.length === 0) {
// happens if the cursor is at the end of the line or the end of the node, use nodeAt pos - 1 to find node marks
start.node = parent.nodeAt($pos.parentOffset - 1);
if (!start.node) {
return null;
}
}
let targetMark = start.node.marks.find(mark => mark.type.name === markType.name);
if (!targetMark) {
return null;
}
let startIndex = $pos.index(),
startPos = $pos.start() + start.offset;
while (startIndex > 0 && targetMark.isInSet(parent.child(startIndex - 1).marks)) {
startPos -= parent.child(--startIndex).nodeSize;
}
let endIndex = $pos.indexAfter(),
endPos = startPos + start.node.nodeSize;
while (endPos < parent.childCount && targetMark.isInSet(parent.child(endIndex).marks)) {
endPos += parent.child(endIndex++).nodeSize;
}
let selection = Selection.between(doc.resolve(startPos), doc.resolve(endPos));
dispatchTransaction(this.view.editor.state.tr.setSelection(selection));
return targetMark;
}