mirror of
https://github.com/Microsoft/vscode
synced 2024-10-30 11:10:48 +00:00
Quick Pick tests (#49340)
This commit is contained in:
parent
50cf92c2f9
commit
18c973953f
5 changed files with 83 additions and 1 deletions
|
@ -298,6 +298,44 @@ suite('window namespace tests', () => {
|
|||
});
|
||||
|
||||
|
||||
test('showQuickPick, accept first', async function () {
|
||||
const pick = window.showQuickPick(['eins', 'zwei', 'drei']);
|
||||
await commands.executeCommand('workbench.action.acceptSelectedQuickOpenItem');
|
||||
assert.equal(await pick, 'eins');
|
||||
});
|
||||
|
||||
test('showQuickPick, accept second', async function () {
|
||||
const resolves: ((value: string) => void)[] = [];
|
||||
const first = new Promise(resolve => resolves.push(resolve));
|
||||
const pick = window.showQuickPick(['eins', 'zwei', 'drei'], {
|
||||
onDidSelectItem: item => resolves.shift()!(item as string)
|
||||
});
|
||||
assert.equal(await first, 'eins');
|
||||
const second = new Promise(resolve => resolves.push(resolve));
|
||||
await commands.executeCommand('workbench.action.quickOpenSelectNext');
|
||||
assert.equal(await second, 'zwei');
|
||||
await commands.executeCommand('workbench.action.acceptSelectedQuickOpenItem');
|
||||
assert.equal(await pick, 'zwei');
|
||||
});
|
||||
|
||||
test('showQuickPick, select first two', async function () {
|
||||
const resolves: ((value: string) => void)[] = [];
|
||||
const picks = window.showQuickPick(['eins', 'zwei', 'drei'], {
|
||||
onDidSelectItem: item => resolves.shift()!(item as string),
|
||||
canPickMany: true
|
||||
});
|
||||
const first = new Promise(resolve => resolves.push(resolve));
|
||||
await commands.executeCommand('workbench.action.quickOpenSelectNext');
|
||||
assert.equal(await first, 'eins');
|
||||
await commands.executeCommand('workbench.action.quickPickManyToggle');
|
||||
const second = new Promise(resolve => resolves.push(resolve));
|
||||
await commands.executeCommand('workbench.action.quickOpenSelectNext');
|
||||
assert.equal(await second, 'zwei');
|
||||
await commands.executeCommand('workbench.action.quickPickManyToggle');
|
||||
await commands.executeCommand('workbench.action.acceptSelectedQuickOpenItem');
|
||||
assert.deepStrictEqual(await picks, ['eins', 'zwei']);
|
||||
});
|
||||
|
||||
test('showQuickPick, undefined on cancel', function () {
|
||||
const source = new CancellationTokenSource();
|
||||
const p = window.showQuickPick(['eins', 'zwei', 'drei'], undefined, source.token);
|
||||
|
|
|
@ -27,6 +27,8 @@ export interface IQuickInputService {
|
|||
|
||||
focus(): void;
|
||||
|
||||
toggle(): void;
|
||||
|
||||
navigate(next: boolean): void;
|
||||
|
||||
accept(): TPromise<void>;
|
||||
|
|
|
@ -0,0 +1,15 @@
|
|||
/*---------------------------------------------------------------------------------------------
|
||||
* Copyright (c) Microsoft Corporation. All rights reserved.
|
||||
* Licensed under the MIT License. See License.txt in the project root for license information.
|
||||
*--------------------------------------------------------------------------------------------*/
|
||||
'use strict';
|
||||
|
||||
import { Registry } from 'vs/platform/registry/common/platform';
|
||||
import { SyncActionDescriptor } from 'vs/platform/actions/common/actions';
|
||||
import { IWorkbenchActionRegistry, Extensions as ActionExtensions } from 'vs/workbench/common/actions';
|
||||
import { QuickPickManyToggleAction } from 'vs/workbench/browser/parts/quickinput/quickInput';
|
||||
import { inQuickOpenContext } from 'vs/workbench/browser/parts/quickopen/quickopen';
|
||||
|
||||
const registry = Registry.as<IWorkbenchActionRegistry>(ActionExtensions.WorkbenchActions);
|
||||
|
||||
registry.registerWorkbenchAction(new SyncActionDescriptor(QuickPickManyToggleAction, QuickPickManyToggleAction.ID, QuickPickManyToggleAction.LABEL, null, inQuickOpenContext), 'Toggle Selection in Quick Pick');
|
|
@ -35,6 +35,7 @@ import { onUnexpectedError, canceled } from 'vs/base/common/errors';
|
|||
import Severity from 'vs/base/common/severity';
|
||||
import { IWorkbenchEditorService } from 'vs/workbench/services/editor/common/editorService';
|
||||
import { IContextKeyService, RawContextKey, IContextKey } from 'vs/platform/contextkey/common/contextkey';
|
||||
import { Action } from 'vs/base/common/actions';
|
||||
|
||||
const $ = dom.$;
|
||||
|
||||
|
@ -588,11 +589,17 @@ export class QuickInputService extends Component implements IQuickInputService {
|
|||
}
|
||||
|
||||
focus() {
|
||||
if (this.ui) {
|
||||
if (this.isDisplayed()) {
|
||||
this.ui.inputBox.setFocus();
|
||||
}
|
||||
}
|
||||
|
||||
toggle() {
|
||||
if (this.isDisplayed() && this.controller instanceof PickManyController) {
|
||||
this.ui.checkboxList.toggleCheckbox();
|
||||
}
|
||||
}
|
||||
|
||||
navigate(next: boolean) {
|
||||
if (this.isDisplayed() && this.ui.checkboxList.isDisplayed()) {
|
||||
this.ui.checkboxList.focus(next ? 'Next' : 'Previous');
|
||||
|
@ -649,3 +656,22 @@ export class QuickInputService extends Component implements IQuickInputService {
|
|||
return this.container && this.container.style.display !== 'none';
|
||||
}
|
||||
}
|
||||
|
||||
export class QuickPickManyToggleAction extends Action {
|
||||
|
||||
public static readonly ID = 'workbench.action.quickPickManyToggle';
|
||||
public static readonly LABEL = localize('quickPickManyToggle', "Toggle Selection in Quick Pick");
|
||||
|
||||
constructor(
|
||||
id: string,
|
||||
label: string,
|
||||
@IQuickInputService private quickInputService: IQuickInputService
|
||||
) {
|
||||
super(id, label);
|
||||
}
|
||||
|
||||
public run(event?: any): TPromise<any> {
|
||||
this.quickInputService.toggle();
|
||||
return TPromise.as(true);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -41,6 +41,7 @@ import 'vs/workbench/parts/logs/electron-browser/logs.contribution';
|
|||
import 'vs/workbench/browser/parts/quickopen/quickopen.contribution';
|
||||
import 'vs/workbench/parts/quickopen/browser/quickopen.contribution';
|
||||
import 'vs/workbench/browser/parts/editor/editorPicker';
|
||||
import 'vs/workbench/browser/parts/quickinput/quickInput.contribution';
|
||||
|
||||
import 'vs/workbench/parts/files/electron-browser/explorerViewlet';
|
||||
import 'vs/workbench/parts/files/electron-browser/fileActions.contribution';
|
||||
|
|
Loading…
Reference in a new issue