Skip to content

Commit f6a5fbe

Browse files
rework logic of setting selectedItems in multi-select mode
1 parent 52cd7df commit f6a5fbe

File tree

1 file changed

+8
-2
lines changed

1 file changed

+8
-2
lines changed

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

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -818,9 +818,15 @@ class QuickPick<T extends IQuickPickItem> extends QuickInput implements IQuickPi
818818
}));
819819
this.visibleDisposables.add(this.ui.onDidAccept(() => {
820820
if (this.canSelectMany) {
821-
this._selectedItems = this.ui.list.getCheckedElements() as T[];
822-
this.onDidChangeSelectionEmitter.fire(this.selectedItems);
821+
// if there are no checked elements, it means that an onDidChangeSelection never fired to overwrite
822+
// `_selectedItems`. In that case, we should emit one with an empty array to ensure that
823+
// `.selectedItems` is up to date.
824+
if (!this.ui.list.getCheckedElements().length) {
825+
this._selectedItems = [];
826+
this.onDidChangeSelectionEmitter.fire(this.selectedItems);
827+
}
823828
} else if (this.activeItems[0]) {
829+
// For single-select, we set `selectedItems` to the item that was accepted.
824830
this._selectedItems = [this.activeItems[0]];
825831
this.onDidChangeSelectionEmitter.fire(this.selectedItems);
826832
}

0 commit comments

Comments
 (0)