Skip to content

Commit 0b1326c

Browse files
committed
Refactor input dialogs to use custom QuickInput with proper lifecycle management and back button support
1 parent 7e26cfb commit 0b1326c

1 file changed

Lines changed: 85 additions & 23 deletions

File tree

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

Lines changed: 85 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -320,24 +320,59 @@ export const edit_model_for_config = async (
320320
export const edit_temperature_for_config = async (
321321
config: ToolConfig
322322
): Promise<number | null | undefined> => {
323-
const new_temp_str = await vscode.window.showInputBox({
324-
title: 'Edit Temperature',
325-
value: config.temperature?.toString() ?? '',
326-
prompt: 'Enter a value between 0 and 2. Leave empty to unset.',
327-
validateInput: (value) => {
328-
if (value.trim() == '') {
329-
return null
330-
}
331-
const num = parseFloat(value)
332-
if (isNaN(num) || num < 0 || num > 2) {
333-
return 'Please enter a number between 0 and 2.'
334-
}
335-
return null
336-
}
323+
return await new Promise<number | null | undefined>((resolve) => {
324+
const input = vscode.window.createInputBox()
325+
input.title = 'Edit Temperature'
326+
input.value = config.temperature?.toString() ?? ''
327+
input.prompt = 'Enter a value between 0 and 2. Leave empty to unset.'
328+
input.buttons = [vscode.QuickInputButtons.Back]
329+
330+
let accepted = false
331+
const disposables: vscode.Disposable[] = []
332+
333+
disposables.push(
334+
input.onDidAccept(() => {
335+
const value = input.value
336+
if (value.trim() == '') {
337+
accepted = true
338+
resolve(null)
339+
input.hide()
340+
return
341+
}
342+
const num = parseFloat(value)
343+
if (isNaN(num) || num < 0 || num > 2) {
344+
input.validationMessage = 'Please enter a number between 0 and 2.'
345+
return
346+
}
347+
accepted = true
348+
resolve(num)
349+
input.hide()
350+
}),
351+
input.onDidChangeValue((value) => {
352+
if (value.trim() == '') {
353+
input.validationMessage = undefined
354+
return
355+
}
356+
const num = parseFloat(value)
357+
if (isNaN(num) || num < 0 || num > 2) {
358+
input.validationMessage = 'Please enter a number between 0 and 2.'
359+
} else {
360+
input.validationMessage = undefined
361+
}
362+
}),
363+
input.onDidTriggerButton((button) => {
364+
if (button === vscode.QuickInputButtons.Back) {
365+
input.hide()
366+
}
367+
}),
368+
input.onDidHide(() => {
369+
if (!accepted) resolve(undefined)
370+
disposables.forEach((d) => d.dispose())
371+
input.dispose()
372+
})
373+
)
374+
input.show()
337375
})
338-
if (new_temp_str === undefined) return undefined
339-
if (new_temp_str.trim() == '') return null
340-
return parseFloat(new_temp_str)
341376
}
342377

343378
export const edit_reasoning_effort_for_config = async () => {
@@ -347,13 +382,40 @@ export const edit_reasoning_effort_for_config = async () => {
347382
{ label: 'medium' },
348383
{ label: 'high' }
349384
]
350-
const selected_effort = await vscode.window.showQuickPick(effort_options, {
351-
title: 'Select Reasoning Effort'
352-
})
353385

354-
if (!selected_effort) return undefined
355-
if (selected_effort.label == 'Unset') return null
356-
return selected_effort.label
386+
return await new Promise<string | null | undefined>((resolve) => {
387+
const quick_pick = vscode.window.createQuickPick()
388+
quick_pick.items = effort_options
389+
quick_pick.title = 'Select Reasoning Effort'
390+
quick_pick.buttons = [vscode.QuickInputButtons.Back]
391+
392+
let accepted = false
393+
const disposables: vscode.Disposable[] = []
394+
395+
disposables.push(
396+
quick_pick.onDidAccept(() => {
397+
accepted = true
398+
const selected = quick_pick.selectedItems[0]
399+
if (selected) {
400+
resolve(selected.label === 'Unset' ? null : selected.label)
401+
} else {
402+
resolve(undefined)
403+
}
404+
quick_pick.hide()
405+
}),
406+
quick_pick.onDidTriggerButton((button) => {
407+
if (button === vscode.QuickInputButtons.Back) {
408+
quick_pick.hide()
409+
}
410+
}),
411+
quick_pick.onDidHide(() => {
412+
if (!accepted) resolve(undefined)
413+
disposables.forEach((d) => d.dispose())
414+
quick_pick.dispose()
415+
})
416+
)
417+
quick_pick.show()
418+
})
357419
}
358420

359421
export const edit_max_concurrency_for_config = async (config: ToolConfig) => {

0 commit comments

Comments
 (0)