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 <esther.perelman@sap.com>
  • Loading branch information
EstherPerelman committed Jun 30, 2021
1 parent 144da47 commit 89e2301
Showing 1 changed file with 11 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ import * as glob from './glob';
import { CustomEditor } from '../../../common';
import { CustomEditorWidget } from './custom-editor-widget';
import { v4 } from 'uuid';
import { Emitter } from '@theia/core';
import { Disposable, Emitter } from '@theia/core';

export class CustomEditorOpener implements OpenHandler {

Expand Down Expand Up @@ -57,6 +57,7 @@ export class CustomEditorOpener implements OpenHandler {
}
}

protected readonly pendingGetWidgets = new Map<string, Disposable>();
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,21 @@ 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, Disposable.create(() => {
this.pendingGetWidgets.delete(stringUri);
}));
widget = await this.widgetManager.getOrCreateWidget<CustomEditorWidget>(CustomEditorWidget.FACTORY_ID, { id });
this.pendingGetWidgets.get(stringUri)?.dispose();
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 89e2301

Please sign in to comment.