Setting TextSelection in newly created node

I can successfully insert a node into the document but I would like to set the TextSelection to the first paragraph of the new node but I get the error “Error: Position 2:0 is not valid in current document” . I know there must be a better way. What is it?

I am using the following code:

  run(pm, name) {
        let {from, to, head} = pm.selection
        let choice = pm.schema.node("choice",{name: name, value: 0})
        let tr = pm.tr.replaceSelection(this.create({name: name}, choice)).apply(andScroll)
        //find path of next sibling
        let len = from.path.length-1
        let sib = from.path[len]+1
        pm.setTextSelection(new Pos(from.path.splice(0,len).concat(sib),0))
        return tr
    }

The serialized html looks like

    <div class="ProseMirror-content" contenteditable="true">
    <h4 pm-offset="0"><p pm-offset="1">
    <div class="widgets-multiplechoice" name="asdf" pm-offset="2">
    <p class="widgets-choice" name="asdf" pm-offset="0"></div>
    <ul pm-offset="3"></div>

and the schema is:

    export class Choice extends Paragraph {
        static get kind() { return "." }
    
        create(attrs, content, marks) {
            if (attrs.value > 0) content = [this.schema.node("radiobutton",attrs)]
            return super.create(attrs, content, marks)
        }
    }
    
    Choice.attributes = {
        name: new Attribute(),
        value: new Attribute()
    }
    
    export class MultipleChoice extends Block {
        static get contains() { return "choice"}
    }
    
    MultipleChoice.attributes = {
        name: new Attribute()
    }

Firstly, you shouldn’t mutate the path of a Pos like that (by calling splice), since you’re destroying from and thus the existing selection that way. You probably meant to call slice.

Secondly, replaceSelection's behavior depends on the shape and type of the selection, and is not all that predictable when inserting a block node. There isn’t currently a good solution for this. I’ll think about it some more.