diff --git a/src/vs/base/parts/quickinput/browser/quickInput.ts b/src/vs/base/parts/quickinput/browser/quickInput.ts index 8f87d3c9f41850977fbb764292e9fc0025e1cd06..ad6c9cc5e3f56b12749bd3e90af296e4a8151617 100644 --- a/src/vs/base/parts/quickinput/browser/quickInput.ts +++ b/src/vs/base/parts/quickinput/browser/quickInput.ts @@ -817,7 +817,10 @@ class QuickPick extends QuickInput implements IQuickPi } })); this.visibleDisposables.add(this.ui.onDidAccept(() => { - if (!this.canSelectMany && this.activeItems[0]) { + if (this.canSelectMany) { + this._selectedItems = this.ui.list.getCheckedElements() as T[]; + this.onDidChangeSelectionEmitter.fire(this.selectedItems); + } else if (this.activeItems[0]) { this._selectedItems = [this.activeItems[0]]; this.onDidChangeSelectionEmitter.fire(this.selectedItems); } diff --git a/src/vs/base/test/parts/quickinput/browser/quickinput.test.ts b/src/vs/base/test/parts/quickinput/browser/quickinput.test.ts index 21d4d03c0e9c5d895b6ae2026efcb30ab567efe1..368a8f0bccf5771a0ff66199be6a2397e758684c 100644 --- a/src/vs/base/test/parts/quickinput/browser/quickinput.test.ts +++ b/src/vs/base/test/parts/quickinput/browser/quickinput.test.ts @@ -59,12 +59,41 @@ suite('QuickInput', () => { }); teardown(() => { - quickpick.dispose(); + quickpick?.dispose(); controller.dispose(); document.body.removeChild(fixture); }); - test('onDidChangeValue gets triggered when .value is set', async () => { + test('pick - basecase', async () => { + const item = { label: 'foo' }; + const pickPromise = controller.pick([item, { label: 'bar' }]); + // wait a bit to let the pick get set up. + await wait(200); + controller.accept(); + const pick = await pickPromise; + assert.strictEqual(pick, item); + }); + + test('pick - activeItem is honored', async () => { + const item = { label: 'foo' }; + const pickPromise = controller.pick([{ label: 'bar' }, item], { activeItem: item }); + // wait a bit to let the pick get set up. + await wait(200); + controller.accept(); + const pick = await pickPromise; + assert.strictEqual(pick, item); + }); + + test('input - basecase', async () => { + const inputPromise = controller.input({ value: 'foo' }); + // wait a bit to let the pick get set up. + await wait(200); + controller.accept(); + const value = await inputPromise; + assert.strictEqual(value, 'foo'); + }); + + test('onDidChangeValue - gets triggered when .value is set', async () => { quickpick = controller.createQuickPick(); let value: string | undefined = undefined; @@ -82,7 +111,7 @@ suite('QuickInput', () => { } }); - test('keepScrollPosition works with activeItems', async () => { + test('keepScrollPosition - works with activeItems', async () => { quickpick = controller.createQuickPick(); const items = []; @@ -107,7 +136,7 @@ suite('QuickInput', () => { assert.strictEqual(getScrollTop(), 0); }); - test('keepScrollPosition works with items', async () => { + test('keepScrollPosition - works with items', async () => { quickpick = controller.createQuickPick(); const items = []; @@ -130,4 +159,28 @@ suite('QuickInput', () => { quickpick.items = items; assert.strictEqual(getScrollTop(), 0); }); + + test('selectedItems - verify previous selectedItems does not hang over to next set of items', async () => { + quickpick = controller.createQuickPick(); + quickpick.items = [{ label: 'step 1' }]; + quickpick.show(); + + void (await new Promise(resolve => { + quickpick.onDidAccept(() => { + console.log(quickpick.selectedItems.map(i => i.label).join(', ')); + quickpick.canSelectMany = true; + quickpick.items = [{ label: 'a' }, { label: 'b' }, { label: 'c' }]; + resolve(); + }); + + // accept 'step 1' + controller.accept(); + })); + + // accept in multi-select + controller.accept(); + + // Since we don't select any items, the selected items should be empty + assert.strictEqual(quickpick.selectedItems.length, 0); + }); });