From f4b63ac06955bd1ea220b851a79bd0ae5315fb0c Mon Sep 17 00:00:00 2001 From: Christof Marti Date: Mon, 23 Apr 2018 15:35:36 +0200 Subject: [PATCH] Update for tests (#48116) --- .../src/singlefolder-tests/window.test.ts | 17 +++++++++--- .../platform/quickinput/common/quickInput.ts | 3 +++ .../browser/parts/quickinput/quickInput.ts | 27 +++++++++++++++---- .../parts/quickopen/quickopen.contribution.ts | 7 +++++ 4 files changed, 45 insertions(+), 9 deletions(-) diff --git a/extensions/vscode-api-tests/src/singlefolder-tests/window.test.ts b/extensions/vscode-api-tests/src/singlefolder-tests/window.test.ts index 97bace17e732c..286936c8659ec 100644 --- a/extensions/vscode-api-tests/src/singlefolder-tests/window.test.ts +++ b/extensions/vscode-api-tests/src/singlefolder-tests/window.test.ts @@ -369,12 +369,21 @@ suite('window namespace tests', () => { } return null; } - }).then(value => { - assert.equal(value, undefined); }); - const exec = commands.executeCommand('workbench.action.acceptSelectedQuickOpenItem'); - return Promise.all([result, exec]); + const accept = commands.executeCommand('workbench.action.acceptSelectedQuickOpenItem'); + return Promise.race([ + result.then(() => assert.ok(false)), + accept.then(() => assert.ok(false), err => assert.ok(err)) + .then(() => new Promise(resolve => setTimeout(resolve, 10))) + ]) + .then(() => { + const close = commands.executeCommand('workbench.action.closeQuickOpen'); + return Promise.all([result, close]) + .then(([value]) => { + assert.equal(value, undefined); + }); + }); }); diff --git a/src/vs/platform/quickinput/common/quickInput.ts b/src/vs/platform/quickinput/common/quickInput.ts index e8a94713ac617..cd9097598e1ee 100644 --- a/src/vs/platform/quickinput/common/quickInput.ts +++ b/src/vs/platform/quickinput/common/quickInput.ts @@ -17,4 +17,7 @@ export interface IQuickInputService { pick(picks: TPromise, options?: IPickOptions, token?: CancellationToken): TPromise; input(options?: IInputOptions, token?: CancellationToken): TPromise; + focus(): void; + accept(): TPromise; + cancel(): TPromise; } diff --git a/src/vs/workbench/browser/parts/quickinput/quickInput.ts b/src/vs/workbench/browser/parts/quickinput/quickInput.ts index bcfae173a10c1..5e801b9387085 100644 --- a/src/vs/workbench/browser/parts/quickinput/quickInput.ts +++ b/src/vs/workbench/browser/parts/quickinput/quickInput.ts @@ -365,13 +365,16 @@ export class QuickInputService extends Component implements IQuickInputService { if (this.controller) { const resolved = this.controller.resolve(ok); if (resolved) { - resolved - .then(() => this.container.style.display = 'none') - .then(null, onUnexpectedError); - return; + const result = resolved + .then(() => { + this.container.style.display = 'none'; + }); + result.then(null, onUnexpectedError); + return result; } } this.container.style.display = 'none'; + return TPromise.as(undefined); } pick(picks: TPromise, options: IPickOptions = {}, token?: CancellationToken): TPromise { @@ -449,7 +452,21 @@ export class QuickInputService extends Component implements IQuickInputService { return this.controller.result; } - public layout(dimension: dom.Dimension): void { + focus() { + if (this.ui) { + this.ui.inputBox.setFocus(); + } + } + + accept() { + return this.close(true); + } + + cancel() { + return this.close(); + } + + layout(dimension: dom.Dimension): void { this.layoutDimensions = dimension; this.updateLayout(); } diff --git a/src/vs/workbench/browser/parts/quickopen/quickopen.contribution.ts b/src/vs/workbench/browser/parts/quickopen/quickopen.contribution.ts index 63545e09e78f1..3f4ad79d9b0e8 100644 --- a/src/vs/workbench/browser/parts/quickopen/quickopen.contribution.ts +++ b/src/vs/workbench/browser/parts/quickopen/quickopen.contribution.ts @@ -12,6 +12,7 @@ import { IWorkbenchActionRegistry, Extensions as ActionExtensions } from 'vs/wor import { KeybindingsRegistry } from 'vs/platform/keybinding/common/keybindingsRegistry'; import { RemoveFromEditorHistoryAction } from 'vs/workbench/browser/parts/quickopen/quickOpenController'; import { QuickOpenSelectNextAction, QuickOpenSelectPreviousAction, inQuickOpenContext, getQuickNavigateHandler, QuickOpenNavigateNextAction, QuickOpenNavigatePreviousAction, defaultQuickOpenContext, QUICKOPEN_ACTION_ID, QUICKOPEN_ACION_LABEL } from 'vs/workbench/browser/parts/quickopen/quickopen'; +import { IQuickInputService } from 'vs/platform/quickinput/common/quickInput'; KeybindingsRegistry.registerCommandAndKeybindingRule({ id: 'workbench.action.closeQuickOpen', @@ -21,6 +22,8 @@ KeybindingsRegistry.registerCommandAndKeybindingRule({ handler: accessor => { const quickOpenService = accessor.get(IQuickOpenService); quickOpenService.close(); + const quickInputService = accessor.get(IQuickInputService); + return quickInputService.cancel(); } }); @@ -32,6 +35,8 @@ KeybindingsRegistry.registerCommandAndKeybindingRule({ handler: accessor => { const quickOpenService = accessor.get(IQuickOpenService); quickOpenService.accept(); + const quickInputService = accessor.get(IQuickInputService); + return quickInputService.accept(); } }); @@ -43,6 +48,8 @@ KeybindingsRegistry.registerCommandAndKeybindingRule({ handler: accessor => { const quickOpenService = accessor.get(IQuickOpenService); quickOpenService.focus(); + const quickInputService = accessor.get(IQuickInputService); + quickInputService.focus(); } });