BUGFIX: Cursor position in editor is moved undesirably in edge cases (#1952)

This commit is contained in:
catloversg
2025-02-08 06:19:54 +07:00
committed by GitHub
parent 48bced3484
commit c99fa448fa

View File

@@ -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);