set cursor position in v6

I wonder what is the command to set cursor position in v6.
Thanks.

editor.dispatch({selection: {anchor: N, head: N}})

1 Like

I did this in two steps

  1. Figure out current cursor position

viewUpdate.view.state.selection.ranges[0].from

  1. Set cursor to the line I want
const newPosition = viewUpdate.view.state.selection.ranges[0].from - 2;

viewUpdate.view.dispatch({
    selection: {
      anchor: newPosition,
      head: newPosition,
    },
  });

not sure if you think this is a decent solution also @marijn

hello, marijn. I pass the following code, the editor does not set the cursor。The highlighting of the focused row is normal, but the cursor display is not normal

view?.dispatch({
  selection: { anchor: pos, head: pos },
  effects: EditorView.scrollIntoView(targetLine.from, {
    y: 'center',
  }),
});

The style of the focused cursor through the click event。The above code lacks automatic new animation-name.

Could it be that the editor is simply not focused? The cursor won’t be visible then.