How's the focus moving to the end?

How’s the focus moving to the end? image

You can call tr.setSelection(TextSelection.create(tr.doc, pos)) to manually set the selection position. To get the pos of end of the line, try snippet below:

const { from, to } = state.selection
let result = {}, to, (node, pos) => {
  // get end pos of node here
  console.log(node, pos)

Thank you for your answer, are you Chinese,look at your id like Chinese.:grinning:

In case it helps anyone, I’ve implemented moving the cursor to the end of the editor with this:

const tr =;

const lastPosition = view.state.doc.content.size;
const selection = TextSelection.create(tr.doc, lastPosition);


The end might not be a valid text selection, so it’s better to use Selection.atEnd for this.