File tree Expand file tree Collapse file tree
src/features/MonakoEditor Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -273,20 +273,15 @@ export const MonacoEditor = ({
273273 if ( ! editor ) return ;
274274
275275 if ( editor . getValue ( ) !== value ) {
276- // Save the cursor position before calling setValue, because it resets the cursor to 0:0
277- const position = editor . getPosition ( ) ;
278- editor . setValue ( value ) ;
279-
280- if ( position ) {
281- const model = editor . getModel ( ) ;
282- if ( ! model ) return ;
283-
284- // Keep the cursor within valid bounds in case the new value is shorter than the previous one
285- const line = Math . min ( position . lineNumber , model . getLineCount ( ) ) ;
286- const column = Math . min ( position . column , model . getLineMaxColumn ( line ) ) ;
287-
288- editor . setPosition ( { lineNumber : line , column } ) ;
289- }
276+ const model = editor . getModel ( ) ;
277+ if ( ! model ) return ;
278+
279+ // Update content without resetting cursor position
280+ model . pushEditOperations (
281+ [ ] ,
282+ [ { range : model . getFullModelRange ( ) , text : value } ] ,
283+ ( ) => null ,
284+ ) ;
290285 }
291286 } ) ;
292287
You can’t perform that action at this time.
0 commit comments