Skip to content

Commit

Permalink
Fix #9670: Custom editor plugin activation called 3 times when double…
Browse files Browse the repository at this point in the history
… click quickly

Signed-off-by: Esther Perelman <[email protected]>
  • Loading branch information
EstherPerelman committed Jun 30, 2021
1 parent 144da47 commit 75ec66c
Showing 1 changed file with 8 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ export class CustomEditorOpener implements OpenHandler {
}
}

protected readonly pendingGetWidgets = new Map<string, Function>();
async open(uri: URI, options?: OpenerOptions): Promise<Widget | undefined> {
let widget: CustomEditorWidget | undefined;
const widgets = this.widgetManager.getWidgets(CustomEditorWidget.FACTORY_ID) as CustomEditorWidget[];
Expand All @@ -68,14 +69,19 @@ export class CustomEditorOpener implements OpenHandler {
if (widget?.isAttached) {
return this.shell.activateWidget(widget.id);
}
const stringUri = uri.toString();
if (!widget && this.pendingGetWidgets.has(stringUri)) {
return;
}
if (!widget) {
const id = v4();
this.pendingGetWidgets.set(stringUri, () => { this.pendingGetWidgets.delete(stringUri); });
widget = await this.widgetManager.getOrCreateWidget<CustomEditorWidget>(CustomEditorWidget.FACTORY_ID, { id });
this.pendingGetWidgets.get(stringUri)!();
widget.viewType = this.editor.viewType;
widget.resource = uri;
this.onDidOpenCustomEditorEmitter.fire(widget);
}

this.onDidOpenCustomEditorEmitter.fire(widget);
}

matches(selectors: CustomEditorSelector[], resource: URI): boolean {
Expand Down

0 comments on commit 75ec66c

Please sign in to comment.