From c99fa448fab0365effa311524d2dd31db3aa0717 Mon Sep 17 00:00:00 2001 From: catloversg <152669316+catloversg@users.noreply.github.com> Date: Sat, 8 Feb 2025 06:19:54 +0700 Subject: [PATCH] BUGFIX: Cursor position in editor is moved undesirably in edge cases (#1952) --- src/ScriptEditor/ui/ScriptEditorRoot.tsx | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/src/ScriptEditor/ui/ScriptEditorRoot.tsx b/src/ScriptEditor/ui/ScriptEditorRoot.tsx index 4074d234a7..763919bdec 100644 --- a/src/ScriptEditor/ui/ScriptEditorRoot.tsx +++ b/src/ScriptEditor/ui/ScriptEditorRoot.tsx @@ -111,7 +111,14 @@ function Root(props: IProps): React.ReactElement { } if (needToReloadModel) { const currentModel = editorRef.current.getModel(); + // Save the current cursor position. The position resets when the model is changed. + const currentPosition = editorRef.current.getPosition(); + // Reload the model. currentModel?.setValue(currentModel.getValue()); + // Restore the saved position. + if (currentPosition) { + editorRef.current.setPosition(currentPosition); + } } }, 2000);