Set caret position to end of selected node

After running command({ href: url }), I would like to deselect current selection and set caret position to end of selected node. NOTE: I am using TipTap I think I would be able to do something similar to this but I don’t appear to have access to TextSelection.create() or the view when using TipTap. Any ideas?

setLinkUrl(command, url) {
    command({ href: url })

    // 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)




1 Like

Forgot to import TextSelection. This is working as expected now. This topic can probably be deleted. Thanks!