File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -88,17 +88,19 @@ export default function CodeEditor({
8888 if ( currentFileIdRef . current !== incomingFileId ) return ;
8989
9090 const editor = editorRef . current ;
91- const currentCode = editor ?. getValue ( ) ;
92-
93- if ( editor && currentCode !== incomingCode ) {
94- const model = editor . getModel ( ) ;
95- if ( model ) {
96- model . pushEditOperations (
97- [ ] ,
98- [ { range : model . getFullModelRange ( ) , text : incomingCode } ] ,
99- ( ) => null
100- ) ;
101- }
91+ const model = editor ?. getModel ( ) ;
92+ const currentCode = model ?. getValue ( ) ;
93+
94+ if ( ! editor || ! model || currentCode === undefined ) return ;
95+
96+ if ( currentCode !== incomingCode ) {
97+ const selection = editor . getSelection ( ) ;
98+ model . pushEditOperations (
99+ [ ] ,
100+ [ { range : model . getFullModelRange ( ) , text : incomingCode } ] ,
101+ ( ) => null
102+ ) ;
103+ editor . setSelection ( selection ) ;
102104 setCode ( incomingCode ) ;
103105 }
104106 } ;
You can’t perform that action at this time.
0 commit comments