Skip to content

Commit 52cd7df

Browse files
fixes microsoft#75046 - ensure selectedItems is updated onAccept
1 parent 243b64d commit 52cd7df

File tree

2 files changed

+61
-5
lines changed

2 files changed

+61
-5
lines changed

src/vs/base/parts/quickinput/browser/quickInput.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -817,7 +817,10 @@ class QuickPick<T extends IQuickPickItem> extends QuickInput implements IQuickPi
817817
}
818818
}));
819819
this.visibleDisposables.add(this.ui.onDidAccept(() => {
820-
if (!this.canSelectMany && this.activeItems[0]) {
820+
if (this.canSelectMany) {
821+
this._selectedItems = this.ui.list.getCheckedElements() as T[];
822+
this.onDidChangeSelectionEmitter.fire(this.selectedItems);
823+
} else if (this.activeItems[0]) {
821824
this._selectedItems = [this.activeItems[0]];
822825
this.onDidChangeSelectionEmitter.fire(this.selectedItems);
823826
}

src/vs/base/test/parts/quickinput/browser/quickinput.test.ts

Lines changed: 57 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -59,12 +59,41 @@ suite('QuickInput', () => {
5959
});
6060

6161
teardown(() => {
62-
quickpick.dispose();
62+
quickpick?.dispose();
6363
controller.dispose();
6464
document.body.removeChild(fixture);
6565
});
6666

67-
test('onDidChangeValue gets triggered when .value is set', async () => {
67+
test('pick - basecase', async () => {
68+
const item = { label: 'foo' };
69+
const pickPromise = controller.pick([item, { label: 'bar' }]);
70+
// wait a bit to let the pick get set up.
71+
await wait(200);
72+
controller.accept();
73+
const pick = await pickPromise;
74+
assert.strictEqual(pick, item);
75+
});
76+
77+
test('pick - activeItem is honored', async () => {
78+
const item = { label: 'foo' };
79+
const pickPromise = controller.pick([{ label: 'bar' }, item], { activeItem: item });
80+
// wait a bit to let the pick get set up.
81+
await wait(200);
82+
controller.accept();
83+
const pick = await pickPromise;
84+
assert.strictEqual(pick, item);
85+
});
86+
87+
test('input - basecase', async () => {
88+
const inputPromise = controller.input({ value: 'foo' });
89+
// wait a bit to let the pick get set up.
90+
await wait(200);
91+
controller.accept();
92+
const value = await inputPromise;
93+
assert.strictEqual(value, 'foo');
94+
});
95+
96+
test('onDidChangeValue - gets triggered when .value is set', async () => {
6897
quickpick = controller.createQuickPick();
6998

7099
let value: string | undefined = undefined;
@@ -82,7 +111,7 @@ suite('QuickInput', () => {
82111
}
83112
});
84113

85-
test('keepScrollPosition works with activeItems', async () => {
114+
test('keepScrollPosition - works with activeItems', async () => {
86115
quickpick = controller.createQuickPick();
87116

88117
const items = [];
@@ -107,7 +136,7 @@ suite('QuickInput', () => {
107136
assert.strictEqual(getScrollTop(), 0);
108137
});
109138

110-
test('keepScrollPosition works with items', async () => {
139+
test('keepScrollPosition - works with items', async () => {
111140
quickpick = controller.createQuickPick();
112141

113142
const items = [];
@@ -130,4 +159,28 @@ suite('QuickInput', () => {
130159
quickpick.items = items;
131160
assert.strictEqual(getScrollTop(), 0);
132161
});
162+
163+
test('selectedItems - verify previous selectedItems does not hang over to next set of items', async () => {
164+
quickpick = controller.createQuickPick();
165+
quickpick.items = [{ label: 'step 1' }];
166+
quickpick.show();
167+
168+
void (await new Promise<void>(resolve => {
169+
quickpick.onDidAccept(() => {
170+
console.log(quickpick.selectedItems.map(i => i.label).join(', '));
171+
quickpick.canSelectMany = true;
172+
quickpick.items = [{ label: 'a' }, { label: 'b' }, { label: 'c' }];
173+
resolve();
174+
});
175+
176+
// accept 'step 1'
177+
controller.accept();
178+
}));
179+
180+
// accept in multi-select
181+
controller.accept();
182+
183+
// Since we don't select any items, the selected items should be empty
184+
assert.strictEqual(quickpick.selectedItems.length, 0);
185+
});
133186
});

0 commit comments

Comments
 (0)