Skip to content

Commit

Permalink
less hectic quick open visibility changes
Browse files Browse the repository at this point in the history
  • Loading branch information
bpasero committed Nov 22, 2015
1 parent 9d1ae7b commit 6be95ed
Showing 1 changed file with 22 additions and 5 deletions.
27 changes: 22 additions & 5 deletions src/vs/workbench/browser/parts/quickopen/quickOpenController.ts
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@ export class QuickOpenController extends WorkbenchComponent implements IQuickOpe
private previousActiveHandlerDescriptor: QuickOpenHandlerDescriptor;
private actionProvider = new ContributableActionProvider();
private previousValue = '';
private visibilityChangeTimeoutHandle: number;

constructor(
private eventService: IEventService,
Expand Down Expand Up @@ -208,7 +209,7 @@ export class QuickOpenController extends WorkbenchComponent implements IQuickOpe
onOk: () => { /* ignore, handle later */ },
onCancel: () => { /* ignore, handle later */ },
onType: (value: string) => { /* ignore, handle later */ },
onShow: () => this._onShow.fire()
onShow: () => this.emitQuickOpenVisibilityChange(true)
}, {
inputPlaceHolder: options.placeHolder || ''
},
Expand Down Expand Up @@ -348,11 +349,11 @@ export class QuickOpenController extends WorkbenchComponent implements IQuickOpe
this.pickOpenWidget.refresh(model, value ? { autoFocusFirstEntry: true } : autoFocus);
},
onShow: () => {
this._onShow.fire(); // event
this.emitQuickOpenVisibilityChange(true); // event
},
onHide: () => {
this.restoreFocus(); // focus back to editor or viewlet
this._onHide.fire(); // event
this.emitQuickOpenVisibilityChange(false); // event
}
});

Expand All @@ -378,6 +379,22 @@ export class QuickOpenController extends WorkbenchComponent implements IQuickOpe
});
}

private emitQuickOpenVisibilityChange(isVisible: boolean): void {
if (this.visibilityChangeTimeoutHandle) {
window.clearTimeout(this.visibilityChangeTimeoutHandle);
}

this.visibilityChangeTimeoutHandle = setTimeout(() => {
if (isVisible) {
this._onShow.fire();
} else {
this._onHide.fire();
}

this.visibilityChangeTimeoutHandle = void 0;
}, 100 /* to prevent flashing, we accumulate visibility changes over a timeout of 100ms */);
}

public refresh(input?: string): TPromise<void> {
if (!this.quickOpenWidget.isVisible()) {
return TPromise.as(null);
Expand Down Expand Up @@ -421,7 +438,7 @@ export class QuickOpenController extends WorkbenchComponent implements IQuickOpe
onType: (value: string) => this.onType(value || ''),
onShow: () => {
this.inQuickOpenMode.set(true);
this._onShow.fire();
this.emitQuickOpenVisibilityChange(true);
},
onHide: () => {
this.inQuickOpenMode.reset();
Expand All @@ -432,7 +449,7 @@ export class QuickOpenController extends WorkbenchComponent implements IQuickOpe
}

this.restoreFocus(); // focus back to editor or viewlet
this._onHide.fire();
this.emitQuickOpenVisibilityChange(false);
}
}, {
inputPlaceHolder: this.hasHandler(HELP_PREFIX) ? nls.localize('quickOpenInput', "Type '?' to get help on the actions you can take from here") : ''
Expand Down

0 comments on commit 6be95ed

Please sign in to comment.