Skip to content

Commit b5993fe

Browse files
committed
Restore last selected items in configuration quick pick menus for better user experience
1 parent 6a8302e commit b5993fe

2 files changed

Lines changed: 62 additions & 6 deletions

File tree

‎apps/editor/src/views/utils/config-editing.ts‎

Lines changed: 37 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,8 @@ import { Logger } from '@shared/utils/logger'
1313
import { dictionary } from '@shared/constants/dictionary'
1414

1515
export const initial_select_provider = async (
16-
providers_manager: ModelProvidersManager
16+
providers_manager: ModelProvidersManager,
17+
last_selected_provider_name?: string
1718
): Promise<Provider | undefined> => {
1819
const providers = await providers_manager.get_providers()
1920

@@ -39,6 +40,12 @@ export const initial_select_provider = async (
3940
tooltip: 'Close'
4041
}
4142
quick_pick.buttons = [close_button]
43+
if (last_selected_provider_name) {
44+
const active = provider_items.find(
45+
(p) => p.label == last_selected_provider_name
46+
)
47+
if (active) quick_pick.activeItems = [active]
48+
}
4249
let accepted = false
4350
const disposables: vscode.Disposable[] = []
4451

@@ -95,6 +102,12 @@ export const initial_select_model = async (
95102
quick_pick.title = 'Models'
96103
quick_pick.placeholder = 'Choose an AI model'
97104
quick_pick.buttons = [vscode.QuickInputButtons.Back]
105+
if (provider.name) {
106+
// Currently initial_select_model doesn't take a previous selection,
107+
// but if we wanted to highlight one, we would do it here.
108+
// Since this is the "Add" flow, usually we don't have a previous model yet.
109+
// Skipping activeItems for initial add flow model selection as per current logic.
110+
}
98111

99112
let accepted = false
100113
const disposables: vscode.Disposable[] = []
@@ -150,7 +163,8 @@ export const initial_select_model = async (
150163
}
151164

152165
export const edit_provider_for_config = async (
153-
providers_manager: ModelProvidersManager
166+
providers_manager: ModelProvidersManager,
167+
current_provider_name?: string
154168
) => {
155169
const providers = await providers_manager.get_providers()
156170
const provider_items = providers.map((p) => ({
@@ -166,6 +180,12 @@ export const edit_provider_for_config = async (
166180
quick_pick.title = 'Model Providers'
167181
quick_pick.placeholder = 'Select a model provider'
168182
quick_pick.buttons = [vscode.QuickInputButtons.Back]
183+
if (current_provider_name) {
184+
const active = provider_items.find(
185+
(p) => p.label === current_provider_name
186+
)
187+
if (active) quick_pick.activeItems = [active]
188+
}
169189
let accepted = false
170190
const disposables: vscode.Disposable[] = []
171191

@@ -248,6 +268,12 @@ export const edit_model_for_config = async (
248268
quick_pick.title = 'Models'
249269
quick_pick.placeholder = 'Choose a model'
250270
quick_pick.buttons = [vscode.QuickInputButtons.Back]
271+
if (config.model) {
272+
const active = model_items.find(
273+
(item) => (item.description || item.label) === config.model
274+
)
275+
if (active) quick_pick.activeItems = [active]
276+
}
251277
let accepted = false
252278
const disposables: vscode.Disposable[] = []
253279

@@ -377,7 +403,9 @@ export const edit_temperature_for_config = async (
377403
})
378404
}
379405

380-
export const edit_reasoning_effort_for_config = async () => {
406+
export const edit_reasoning_effort_for_config = async (
407+
current_effort?: string
408+
) => {
381409
const effort_options: vscode.QuickPickItem[] = [
382410
{
383411
label: 'Unset',
@@ -396,6 +424,12 @@ export const edit_reasoning_effort_for_config = async () => {
396424
quick_pick.title = 'Reasoning Efforts'
397425
quick_pick.placeholder = 'Select reasoning effort'
398426
quick_pick.buttons = [vscode.QuickInputButtons.Back]
427+
if (current_effort) {
428+
const active = effort_options.find(
429+
(item) => item.label.toLowerCase() === current_effort.toLowerCase()
430+
)
431+
if (active) quick_pick.activeItems = [active]
432+
}
399433

400434
let accepted = false
401435
const disposables: vscode.Disposable[] = []

‎apps/editor/src/views/utils/upsert-configuration.ts‎

Lines changed: 25 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -146,7 +146,10 @@ export const upsert_configuration = async (params: {
146146

147147
// eslint-disable-next-line no-constant-condition
148148
while (true) {
149-
selected_provider = await initial_select_provider(providers_manager)
149+
selected_provider = await initial_select_provider(
150+
providers_manager,
151+
selected_provider?.name
152+
)
150153
if (!selected_provider) return
151154

152155
selected_model = await initial_select_model(
@@ -166,6 +169,7 @@ export const upsert_configuration = async (params: {
166169

167170
const updated_config = config_to_edit
168171
const starting_config = { ...updated_config }
172+
let last_selected_label: string | undefined
169173

170174
// eslint-disable-next-line no-constant-condition
171175
while (true) {
@@ -197,6 +201,10 @@ export const upsert_configuration = async (params: {
197201
quick_pick.buttons = has_changes
198202
? [redo_button, close_button]
199203
: [close_button]
204+
if (last_selected_label) {
205+
const active = items.find((i) => i.label === last_selected_label)
206+
if (active) quick_pick.activeItems = [active]
207+
}
200208
let accepted = false
201209
const disposables: vscode.Disposable[] = []
202210

@@ -239,10 +247,14 @@ export const upsert_configuration = async (params: {
239247
break
240248
}
241249

250+
last_selected_label = selected_item.label
242251
const selected_option = selected_item.label
243252

244253
if (selected_option == 'Model Provider') {
245-
const new_provider = await edit_provider_for_config(providers_manager)
254+
const new_provider = await edit_provider_for_config(
255+
providers_manager,
256+
updated_config.provider_name
257+
)
246258
if (new_provider) {
247259
updated_config.provider_name = new_provider.provider_name
248260
updated_config.provider_type = new_provider.provider_type
@@ -258,6 +270,7 @@ export const upsert_configuration = async (params: {
258270
}
259271
} else if (selected_option == 'Advanced') {
260272
// eslint-disable-next-line no-constant-condition
273+
let last_advanced_label: string | undefined
261274
while (true) {
262275
const advanced_items: vscode.QuickPickItem[] = []
263276
if (advanced_options.includes('Temperature')) {
@@ -292,6 +305,12 @@ export const upsert_configuration = async (params: {
292305
: 'Create New Configuration - Advanced'
293306
quick_pick.placeholder = 'Select a property to edit'
294307
quick_pick.buttons = [vscode.QuickInputButtons.Back]
308+
if (last_advanced_label) {
309+
const active = advanced_items.find(
310+
(i) => i.label === last_advanced_label
311+
)
312+
if (active) quick_pick.activeItems = [active]
313+
}
295314
let accepted = false
296315
const disposables: vscode.Disposable[] = []
297316

@@ -316,6 +335,7 @@ export const upsert_configuration = async (params: {
316335
})
317336

318337
if (!selected_advanced) break
338+
last_advanced_label = selected_advanced.label
319339

320340
if (selected_advanced.label == 'Temperature') {
321341
const new_temp = await edit_temperature_for_config(updated_config)
@@ -326,7 +346,9 @@ export const upsert_configuration = async (params: {
326346
} else if (selected_advanced.label == 'Reasoning Effort') {
327347
// eslint-disable-next-line no-constant-condition
328348
while (true) {
329-
const new_effort = await edit_reasoning_effort_for_config()
349+
const new_effort = await edit_reasoning_effort_for_config(
350+
updated_config.reasoning_effort
351+
)
330352
if (new_effort === undefined) break
331353

332354
let is_valid = true

0 commit comments

Comments
 (0)