Skip to content

Commit ead1f02

Browse files
committed
Bug fix
1 parent 925a573 commit ead1f02

1 file changed

Lines changed: 13 additions & 11 deletions

File tree

src/components/Editor.tsx

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff 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
};

0 commit comments

Comments
 (0)