I got a similar issue that i had before (for which i asked this question).
In that time, the selection is lost after calling view.updateState() as the node to which is attached the current custom node view gets updated which will reinstanciate the custom node view as a consequence and that’s how both the selection and the view focus are lost (because the selection was inside the previous instance of the node view, in its dom element…)
Now i again have the same issue in another custom node view and i’ve tried a workaround to fix it by storing the current selection in an outer scope variable (just after the view.updateState() call and then in the next custom node reinstanciation, i reset the same saved selection. But strangely it’s not working. The cursor will be blinking (it seems) at the position 0 !
In this codesandbox i did reproduce the issue.
As you can see in this screenshot, when i type at the end of the second line, i’ll get the selection back in the begining of the first line.
In tableCellView the as you can see, i’ve tired to create the new selection with either resolved positions or the constructor or with pos and TextSelection.create()
setTimeout(() => { inner.focus(); // Here the selection will be reset const lastSelection = getTableCellViewLastSelection(); if (lastSelection) { const { state } = view; let { tr, doc } = state; // Here i tried to create the selection with resolved positions and the constructor // const newTextSelection = new TextSelection(lastSelection.$anchor, lastSelection.$head); // And here i tried with lastSelection.$from.pos and TextSelection.create() const newTextSelection = TextSelection.create( doc, lastSelection.$from.pos ); tr = tr.setSelection(newTextSelection); setTableCellViewLastSelection(undefined); view.updateState(state.apply(tr)); } }, 150);