运行命令({ href: url })后,我想取消选择当前选择并将插入符号位置设置为所选节点的末尾。注意:我正在使用 TipTap
setLinkUrl(command, url) {
command({ href: url })
this.hideLinkMenu()
// Set cursor position after highlighted link
var tag = document.getElementById("editor")
var setpos = document.createRange()
var set = window.getSelection()
const state = this.editor.state
let sel = state.selection
// TODO: Check if sel range > 0
let resolvedPos = state.doc.resolve(sel.from)
let node = resolvedPos.node(resolvedPos.depth)
// This is where I want to set the caret position to the end of the currently selected node
// Currently, I'm using hardcoded indices as proof of concept while the editor contains three paragraph nodes
setpos.setStart(document.getElementById("editor").childNodes[0].childNodes[1], 1)
setpos.setEnd(document.getElementById("editor").childNodes[0].childNodes[1], 1)
setpos.collapse(true)
set.removeAllRanges()
set.addRange(setpos)
tag.focus()