Skip to content

Commit 8a897f5

Browse files
committed
Switch to a flat list of items without section separators when searching in configuration quick pick
- when searching we see repeated entries, we should continue to see repeated entries when not searching though └── apps └── editor └── src ├── commands │ └── code-at-cursor-command │ └── code-at-cursor-commands.ts ├── utils │ └── show-configuration-quick-pick.ts └── views └── prompt └── backend └── message-handlers └── handle-autofill.ts
1 parent a2c8ae3 commit 8a897f5

1 file changed

Lines changed: 33 additions & 9 deletions

File tree

‎apps/editor/src/utils/show-configuration-quick-pick.ts‎

Lines changed: 33 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ export const show_configuration_quick_pick = async <T>(
6262
}
6363
}
6464

65-
const items: PickItem[] = []
65+
const items_with_duplicates: PickItem[] = []
6666

6767
const mapped_configs = configurations.map((c) => ({
6868
config: c,
@@ -72,17 +72,31 @@ export const show_configuration_quick_pick = async <T>(
7272
const unpinned = mapped_configs.filter((c) => !c.mapped.is_pinned)
7373

7474
if (pinned.length > 0) {
75-
items.push({ label: 'pinned', kind: vscode.QuickPickItemKind.Separator })
76-
items.push(...pinned.map((c) => map_to_quick_pick_item(c.config)))
75+
items_with_duplicates.push({
76+
label: 'pinned',
77+
kind: vscode.QuickPickItemKind.Separator
78+
})
79+
items_with_duplicates.push(
80+
...pinned.map((c) => map_to_quick_pick_item(c.config))
81+
)
7782
if (unpinned.length > 0) {
78-
items.push({ label: 'all', kind: vscode.QuickPickItemKind.Separator })
83+
items_with_duplicates.push({
84+
label: 'all',
85+
kind: vscode.QuickPickItemKind.Separator
86+
})
7987
}
8088
}
8189

82-
items.push(...mapped_configs.map((c) => map_to_quick_pick_item(c.config)))
90+
items_with_duplicates.push(
91+
...mapped_configs.map((c) => map_to_quick_pick_item(c.config))
92+
)
93+
94+
const items_without_duplicates = mapped_configs.map((c) =>
95+
map_to_quick_pick_item(c.config)
96+
)
8397

8498
const quick_pick = vscode.window.createQuickPick<PickItem>()
85-
quick_pick.items = items
99+
quick_pick.items = items_with_duplicates
86100
quick_pick.title = title
87101
quick_pick.placeholder = placeholder
88102
quick_pick.matchOnDescription = true
@@ -98,11 +112,13 @@ export const show_configuration_quick_pick = async <T>(
98112
quick_pick.buttons = [close_button]
99113
}
100114

101-
const last_selected_item = items.find((item) => item.id === last_selected_id)
115+
const last_selected_item = items_with_duplicates.find(
116+
(item) => item.id === last_selected_id
117+
)
102118
if (last_selected_item) {
103119
quick_pick.activeItems = [last_selected_item]
104-
} else if (items.length > 0) {
105-
const first_selectable = items.find(
120+
} else if (items_with_duplicates.length > 0) {
121+
const first_selectable = items_with_duplicates.find(
106122
(i) => i.kind !== vscode.QuickPickItemKind.Separator
107123
)
108124
if (first_selectable) {
@@ -114,6 +130,14 @@ export const show_configuration_quick_pick = async <T>(
114130
(resolve) => {
115131
let resolved = false
116132

133+
quick_pick.onDidChangeValue((value) => {
134+
if (value) {
135+
quick_pick.items = items_without_duplicates
136+
} else {
137+
quick_pick.items = items_with_duplicates
138+
}
139+
})
140+
117141
quick_pick.onDidTriggerButton((button) => {
118142
if (button === vscode.QuickInputButtons.Back) {
119143
resolved = true

0 commit comments

Comments
 (0)