uiwjs / react-codemirror

CodeMirror 6 component for React. @codemirror https://uiwjs.github.io/react-codemirror/
https://uiwjs.github.io/react-codemirror/
MIT License
1.69k stars 134 forks source link

Manually set cursor position #628

Closed radim10 closed 9 months ago

radim10 commented 9 months ago

The problem is that when the vale prop changes the cursor is moved to position 0. I can track the cursor before update with state but how to manually set the cursor of the ReactCodeMirrorRef? I tried this but it does not seem to work: view.state.changeByRange((range) => ({ changes: [ { from: range.from, insert: '**' }, { from: range.to, insert: '**' }, ], range: EditorSelection.range(range.from + 2, range.to + 2), })),

CalvinChiramal commented 3 months ago

Did you figure out why the cursor moves to position 0? I'm facing this same issue.