Skip to content

Commit 0302f10

Browse files
committed
Prevent multiple listeners calling in VSCode
1 parent 2826f77 commit 0302f10

File tree

1 file changed

+25
-1
lines changed
  • packages/app/src/app/components/CodeEditor/VSCode

1 file changed

+25
-1
lines changed

packages/app/src/app/components/CodeEditor/VSCode/index.js

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -299,6 +299,14 @@ class MonacoEditor extends React.Component<Props, State> implements Editor {
299299

300300
this.modelContentChangedListener = activeEditor.onDidChangeModelContent(
301301
e => {
302+
if (activeEditor !== editor.getActiveCodeEditor()) {
303+
// This check ensures that we can't have multiple editor listeners working
304+
// with the current editor. I noticed an issue where we suddenly
305+
// had 2 listeners for 2 different editors and it updated code
306+
// for the current editor. This caused code to enter the wrong modules.
307+
return;
308+
}
309+
302310
const { isLive, sendTransforms } = this.props;
303311

304312
if (isLive && sendTransforms && !this.receivingCode) {
@@ -1159,6 +1167,20 @@ class MonacoEditor extends React.Component<Props, State> implements Editor {
11591167
}
11601168
};
11611169

1170+
getCurrentModelPath = () => {
1171+
const activeEditor = this.editor.getActiveCodeEditor();
1172+
1173+
if (!activeEditor) {
1174+
return undefined;
1175+
}
1176+
const model = activeEditor.getModel();
1177+
if (!model) {
1178+
return undefined;
1179+
}
1180+
1181+
return model.uri.path.replace(/^\/sandbox/, '');
1182+
};
1183+
11621184
openModule = (module: Module) => {
11631185
if (module.id) {
11641186
const path = getModulePath(
@@ -1167,7 +1189,9 @@ class MonacoEditor extends React.Component<Props, State> implements Editor {
11671189
module.id
11681190
);
11691191

1170-
this.editor.openFile(path);
1192+
if (this.getCurrentModelPath() !== path) {
1193+
this.editor.openFile(path);
1194+
}
11711195
}
11721196
};
11731197

0 commit comments

Comments
 (0)