Skip to content

Commit a3fb707

Browse files
committed
fix: improve UX of multi-select
1 parent 62628b8 commit a3fb707

File tree

2 files changed

+21
-26
lines changed

2 files changed

+21
-26
lines changed

src/notebooks/deepnote/deepnoteInputBlockCellStatusBarProvider.ts

Lines changed: 15 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import {
1010
NotebookEdit,
1111
Position,
1212
Range,
13+
ThemeIcon,
1314
WorkspaceEdit,
1415
commands,
1516
l10n,
@@ -708,38 +709,31 @@ export class DeepnoteInputBlockCellStatusBarItemProvider
708709
if (allowMultiple) {
709710
// Multi-select using QuickPick with custom behavior for clear selection
710711
const currentSelection = Array.isArray(currentValue) ? currentValue : [];
711-
const clearSelectionLabel = l10n.t('$(circle-slash) Clear selection');
712712

713-
// Create quick pick items
713+
// Create quick pick items (only actual options, not "Clear selection")
714714
const optionItems = options.map((opt) => ({
715715
label: opt,
716716
picked: currentSelection.includes(opt)
717717
}));
718718

719-
// Add empty option if allowed
720-
if (allowEmpty) {
721-
optionItems.unshift({
722-
label: clearSelectionLabel,
723-
picked: false
724-
});
725-
}
726-
727719
// Use createQuickPick for more control
728720
const quickPick = window.createQuickPick();
729721
quickPick.items = optionItems;
730722
quickPick.selectedItems = optionItems.filter((item) => item.picked);
731723
quickPick.canSelectMany = true;
732-
quickPick.placeholder = allowEmpty
733-
? l10n.t('Select one or more options (or clear selection)')
734-
: l10n.t('Select one or more options');
724+
quickPick.placeholder = l10n.t('Select one or more options');
735725

736-
// Listen for selection changes to handle "Clear selection" specially
726+
// Add "Clear selection" as a button if empty values are allowed
737727
if (allowEmpty) {
738-
quickPick.onDidChangeSelection((selectedItems) => {
739-
const hasClearSelection = selectedItems.some((item) => item.label === clearSelectionLabel);
740-
if (hasClearSelection) {
741-
// If "Clear selection" is selected, immediately clear and close
742-
quickPick.selectedItems = [];
728+
const clearButton = {
729+
iconPath: new ThemeIcon('clear-all'),
730+
tooltip: l10n.t('Clear selection')
731+
};
732+
quickPick.buttons = [clearButton];
733+
734+
quickPick.onDidTriggerButton((button) => {
735+
if (button === clearButton) {
736+
// Clear selection and close
743737
quickPick.hide();
744738
void this.updateCellMetadata(cell, { deepnote_variable_value: [] });
745739
}
@@ -748,12 +742,8 @@ export class DeepnoteInputBlockCellStatusBarItemProvider
748742

749743
quickPick.onDidAccept(() => {
750744
const selected = quickPick.selectedItems;
751-
const hasClearSelection = selected.some((item) => item.label === clearSelectionLabel);
752-
753-
if (!hasClearSelection) {
754-
const newValue = selected.map((item) => item.label);
755-
void this.updateCellMetadata(cell, { deepnote_variable_value: newValue });
756-
}
745+
const newValue = selected.map((item) => item.label);
746+
void this.updateCellMetadata(cell, { deepnote_variable_value: newValue });
757747
quickPick.hide();
758748
});
759749

src/notebooks/deepnote/deepnoteInputBlockCellStatusBarProvider.unit.test.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,17 @@ import { expect } from 'chai';
55
import { DeepnoteInputBlockCellStatusBarItemProvider } from './deepnoteInputBlockCellStatusBarProvider';
66
import { NotebookCell, NotebookCellKind, NotebookDocument } from 'vscode';
77
import { Uri } from 'vscode';
8+
import type { IExtensionContext } from '../../platform/common/types';
89

910
suite('DeepnoteInputBlockCellStatusBarItemProvider', () => {
1011
let provider: DeepnoteInputBlockCellStatusBarItemProvider;
12+
let mockExtensionContext: IExtensionContext;
1113

1214
setup(() => {
13-
provider = new DeepnoteInputBlockCellStatusBarItemProvider();
15+
mockExtensionContext = {
16+
subscriptions: []
17+
} as any;
18+
provider = new DeepnoteInputBlockCellStatusBarItemProvider(mockExtensionContext);
1419
});
1520

1621
teardown(() => {

0 commit comments

Comments
 (0)