Skip to content

Commit a442155

Browse files
fix prioritizing selection in explorer over opening file
1 parent bcaf271 commit a442155

File tree

1 file changed

+18
-10
lines changed
  • packages/app/src/app/overmind/effects/vscode

1 file changed

+18
-10
lines changed

packages/app/src/app/overmind/effects/vscode/index.ts

Lines changed: 18 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -310,16 +310,24 @@ export class VSCodeEffect {
310310
public async openModule(module: Module) {
311311
await this.initialized;
312312

313-
try {
314-
const model = await this.modelsHandler.changeModule(module);
315-
316-
this.lint(module.title, model);
317-
} catch (error) {
318-
// We might try to open a module that is not actually opened in the editor,
319-
// but the configuration wizard.. currently this throws an error as there
320-
// is really no good way to identify when it happen. This needs to be
321-
// improved in next version
322-
}
313+
// We use an animation frame here, because we want the rest of the logic to finish running,
314+
// allowing for a paint, like selections in explorer. For this to work we have to ensure
315+
// that we are actually indeed still trying to open this file, as we might have changed
316+
// the file
317+
requestAnimationFrame(async () => {
318+
if (module.id === this.options.getCurrentModule().id) {
319+
try {
320+
const model = await this.modelsHandler.changeModule(module);
321+
322+
this.lint(module.title, model);
323+
} catch (error) {
324+
// We might try to open a module that is not actually opened in the editor,
325+
// but the configuration wizard.. currently this throws an error as there
326+
// is really no good way to identify when it happen. This needs to be
327+
// improved in next version
328+
}
329+
}
330+
});
323331
}
324332

325333
setErrors = (errors: ModuleError[]) => {

0 commit comments

Comments
 (0)