Skip to content

Commit 33108a3

Browse files
Better handling of quick pick with whitespace (#3045)
1 parent 2954940 commit 33108a3

File tree

1 file changed

+12
-11
lines changed

1 file changed

+12
-11
lines changed

packages/cursorless-vscode/src/ide/vscode/vscodeShowQuickPick.ts

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -33,9 +33,12 @@ export function vscodeShowQuickPick(
3333
}
3434

3535
if (options?.defaultValue != null) {
36-
quickPick.activeItems = quickPickItems.filter(
36+
const activeItem = quickPickItems.find(
3737
(item) => item.value === options.defaultValue,
3838
);
39+
if (activeItem != null) {
40+
quickPick.activeItems = [activeItem];
41+
}
3942
}
4043

4144
if (options?.unknownValues) {
@@ -45,19 +48,17 @@ export function vscodeShowQuickPick(
4548
: "Add new value '{}' →";
4649

4750
quickPick.onDidChangeValue(() => {
48-
quickPick.items = [
49-
...quickPickItems,
50-
51-
// INJECT user values into proposed values
52-
...(items.includes(quickPick.value) || quickPick.value.trim() === ""
53-
? []
51+
const value = quickPick.value.trim();
52+
quickPick.items =
53+
value === "" || items.includes(value)
54+
? quickPickItems
5455
: [
56+
...quickPickItems,
5557
{
56-
label: newValueTemplate.replace("{}", quickPick.value),
57-
value: quickPick.value,
58+
label: newValueTemplate.replace("{}", value),
59+
value,
5860
},
59-
]),
60-
];
61+
];
6162
});
6263
}
6364

0 commit comments

Comments
 (0)