Skip to content

Commit ab673ad

Browse files
committed
Improve quick pick navigation consistency for presets and prompt templates, and dim the chat input TAB hint
1 parent 91bff11 commit ab673ad

3 files changed

Lines changed: 122 additions & 20 deletions

File tree

‎packages/ui/src/components/editor/panel/ChatInput/ChatInput.module.scss‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -120,6 +120,7 @@
120120
border: 1px solid var(--cwc-border-color);
121121
border-radius: var(--border-radius-5px);
122122
pointer-events: none;
123+
opacity: var(--dimmed-opacity);
123124
}
124125
}
125126

‎packages/vscode/src/views/panel/backend/message-handlers/handle-send-prompt.ts‎

Lines changed: 99 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -310,6 +310,7 @@ async function show_presets_in_group_quick_pick(params: {
310310

311311
quick_pick.items = items
312312
quick_pick.placeholder = 'Search presets by name'
313+
quick_pick.title = 'Select Preset'
313314
quick_pick.matchOnDescription = true
314315

315316
const last_preset_key = get_last_selected_preset_key(panel_provider.web_mode)
@@ -463,7 +464,7 @@ async function show_preset_quick_pick(params: {
463464

464465
if (last_choice === 'Preset' && last_selected_preset) {
465466
const preset = presets.find((p) => p.name === last_selected_preset)
466-
if (preset) {
467+
if (preset && !preset.isPinned) {
467468
let group_name = 'Ungrouped'
468469
if (preset.chatbot) {
469470
const preset_index = presets.findIndex(
@@ -542,6 +543,11 @@ async function show_preset_quick_pick(params: {
542543
tooltip: 'Run selected presets'
543544
}
544545

546+
const run_without_submission_button: vscode.QuickInputButton = {
547+
iconPath: new vscode.ThemeIcon('debug-continue-small'),
548+
tooltip: 'Run without submission'
549+
}
550+
545551
const quick_pick = vscode.window.createQuickPick<
546552
vscode.QuickPickItem & { preset_name?: string; group_name?: string }
547553
>()
@@ -551,6 +557,36 @@ async function show_preset_quick_pick(params: {
551557
group_name?: string
552558
})[] = []
553559

560+
const pinned_presets = presets.filter((p) => p.isPinned && p.chatbot)
561+
562+
if (pinned_presets.length > 0) {
563+
items.push({ label: 'Pinned', kind: vscode.QuickPickItemKind.Separator })
564+
pinned_presets.forEach((preset) => {
565+
const is_unnamed = !preset.name || /^\(\d+\)$/.test(preset.name.trim())
566+
const chatbot_models = CHATBOTS[preset.chatbot as keyof typeof CHATBOTS]
567+
.models as any
568+
const model = preset.model
569+
? chatbot_models[preset.model]?.label || preset.model
570+
: ''
571+
items.push({
572+
label: `$(pinned) ${is_unnamed ? preset.chatbot! : preset.name}`,
573+
preset_name: preset.name,
574+
description: is_unnamed
575+
? model
576+
: `${preset.chatbot}${model ? ` · ${model}` : ''}`,
577+
buttons: [run_without_submission_button]
578+
})
579+
})
580+
}
581+
582+
const has_groups =
583+
(presets.length > 0 && presets[0].chatbot) ||
584+
presets.some((p) => !p.chatbot)
585+
586+
if (has_groups) {
587+
items.push({ label: 'Groups', kind: vscode.QuickPickItemKind.Separator })
588+
}
589+
554590
if (presets.length > 0 && presets[0].chatbot) {
555591
let group_presets_count = 0
556592
let selected_presets_count = 0
@@ -607,6 +643,7 @@ async function show_preset_quick_pick(params: {
607643

608644
quick_pick.items = items
609645
quick_pick.placeholder = 'Select a group to run presets from'
646+
quick_pick.title = 'Select Group'
610647
quick_pick.matchOnDescription = true
611648

612649
if (group_to_highlight_on_back) {
@@ -642,7 +679,7 @@ async function show_preset_quick_pick(params: {
642679
}
643680

644681
quick_pick.onDidTriggerItemButton(async (e) => {
645-
const item = e.item as any & { group_name?: string }
682+
const item = e.item as any & { group_name?: string; preset_name?: string }
646683
if (item.group_name && e.button === run_group_button) {
647684
quick_pick.hide()
648685

@@ -659,6 +696,30 @@ async function show_preset_quick_pick(params: {
659696
})
660697
}
661698
do_resolve(resolution)
699+
} else if (
700+
item.preset_name &&
701+
e.button === run_without_submission_button
702+
) {
703+
quick_pick.hide()
704+
const preset = presets.find((p) => p.name === item.preset_name)!
705+
if (params.get_is_preset_disabled(preset)) {
706+
if (
707+
!params.is_in_code_completions_mode &&
708+
!params.current_instructions &&
709+
!preset.promptPrefix &&
710+
!preset.promptSuffix
711+
) {
712+
vscode.window.showWarningMessage(
713+
dictionary.warning_message.TYPE_SOMETHING_TO_USE_PRESET
714+
)
715+
}
716+
do_resolve(null)
717+
} else {
718+
do_resolve({
719+
preset_names: [item.preset_name],
720+
without_submission: true
721+
})
722+
}
662723
}
663724
})
664725

@@ -671,7 +732,42 @@ async function show_preset_quick_pick(params: {
671732
return
672733
}
673734

674-
if (selected.group_name) {
735+
if (selected.preset_name) {
736+
quick_pick.hide()
737+
const preset = presets.find((p) => p.name === selected.preset_name)!
738+
if (params.get_is_preset_disabled(preset)) {
739+
if (
740+
!params.is_in_code_completions_mode &&
741+
!params.current_instructions &&
742+
!preset.promptPrefix &&
743+
!preset.promptSuffix
744+
) {
745+
vscode.window.showWarningMessage(
746+
dictionary.warning_message.TYPE_SOMETHING_TO_USE_PRESET
747+
)
748+
}
749+
do_resolve(null)
750+
} else {
751+
let group_name = 'Ungrouped'
752+
const preset_index = presets.findIndex(
753+
(p) => p.name === selected.preset_name
754+
)
755+
if (preset_index > -1) {
756+
for (let i = preset_index - 1; i >= 0; i--) {
757+
if (!presets[i].chatbot) {
758+
group_name = presets[i].name
759+
break
760+
}
761+
}
762+
}
763+
update_last_used_preset_or_group({
764+
panel_provider,
765+
preset_name: selected.preset_name,
766+
group_name: group_name
767+
})
768+
do_resolve({ preset_names: [selected.preset_name] })
769+
}
770+
} else if (selected.group_name) {
675771
is_navigating = true
676772
quick_pick.hide()
677773
const result = await show_presets_in_group_quick_pick({

‎packages/vscode/src/views/panel/backend/message-handlers/handle-show-prompt-template-quick-pick.ts‎

Lines changed: 22 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -123,14 +123,11 @@ export const handle_show_prompt_template_quick_pick = async (
123123
template: PromptTemplate,
124124
index: number
125125
): Promise<boolean> => {
126-
const BACK_LABEL = '$(arrow-left) Back'
127126
const NAME_LABEL = 'Name'
128127
const TEMPLATE_LABEL = 'Template'
129128

130129
const create_edit_options = () => {
131130
return [
132-
{ label: BACK_LABEL },
133-
{ label: '', kind: vscode.QuickPickItemKind.Separator },
134131
{
135132
label: NAME_LABEL,
136133
description: template.name || 'Not set'
@@ -149,18 +146,27 @@ export const handle_show_prompt_template_quick_pick = async (
149146
edit_quick_pick.items = create_edit_options()
150147
edit_quick_pick.title = 'Edit Template'
151148
edit_quick_pick.placeholder = 'Select what to edit'
149+
edit_quick_pick.buttons = [vscode.QuickInputButtons.Back]
152150

153151
return new Promise<boolean>((resolve) => {
154152
let is_accepted = false
153+
let did_trigger_back = false
155154
const edit_disposables: vscode.Disposable[] = []
156155

157156
edit_disposables.push(
157+
edit_quick_pick.onDidTriggerButton((button) => {
158+
if (button === vscode.QuickInputButtons.Back) {
159+
did_trigger_back = true
160+
edit_quick_pick.hide()
161+
resolve(false) // User clicked 'Back', do not cancel the main quick pick
162+
}
163+
}),
158164
edit_quick_pick.onDidAccept(async () => {
159165
is_accepted = true
160166
const selected = edit_quick_pick.selectedItems[0]
161-
if (!selected || selected.label === BACK_LABEL) {
167+
if (!selected) {
162168
edit_quick_pick.hide()
163-
resolve(false) // User clicked 'Back', do not cancel the main quick pick
169+
resolve(false) // User cancelled, do not cancel the main quick pick
164170
return
165171
}
166172

@@ -189,17 +195,13 @@ export const handle_show_prompt_template_quick_pick = async (
189195
vscode.ConfigurationTarget.Global
190196
)
191197
next_template_state = updated_template
192-
} else {
193-
// User cancelled the input box (pressed Escape)
194-
resolve(true) // Indicate full cancellation
195-
return
196198
}
197199

198200
const should_cancel_entirely = await edit_template(
199201
next_template_state,
200202
index
201203
)
202-
resolve(should_cancel_entirely) // Pass through the result of the recursive call
204+
resolve(should_cancel_entirely)
203205
} else if (selected.label == TEMPLATE_LABEL) {
204206
const new_template_text = await vscode.window.showInputBox({
205207
prompt: 'Enter the prompt template',
@@ -221,22 +223,18 @@ export const handle_show_prompt_template_quick_pick = async (
221223
vscode.ConfigurationTarget.Global
222224
)
223225
next_template_state = updated_template
224-
} else if (new_template_text === undefined) {
225-
// User cancelled the input box
226-
resolve(true) // Indicate full cancellation
227-
return
228226
}
229227

230228
const should_cancel_entirely = await edit_template(
231229
next_template_state,
232230
index
233231
)
234-
resolve(should_cancel_entirely) // Pass through the result of the recursive call
232+
resolve(should_cancel_entirely)
235233
}
236234
}),
237235
edit_quick_pick.onDidHide(() => {
238-
if (!is_accepted) {
239-
resolve(true) // If quick pick is hidden without accepting, it means user cancelled entirely
236+
if (!is_accepted && !did_trigger_back) {
237+
resolve(false) // If quick pick is hidden without accepting (e.g. Escape), treat as 'Back'
240238
}
241239
edit_disposables.forEach((d) => d.dispose())
242240
})
@@ -380,6 +378,13 @@ export const handle_show_prompt_template_quick_pick = async (
380378
// User clicked 'Back' from the edit quick pick, or successfully edited and returned to it.
381379
// We need to re-show the main templates_quick_pick.
382380
templates_quick_pick.items = create_template_items(prompt_templates)
381+
// Highlight the item that was just edited
382+
const edited_item = templates_quick_pick.items.find(
383+
(i) => i.index === item.index
384+
)
385+
if (edited_item) {
386+
templates_quick_pick.activeItems = [edited_item]
387+
}
383388
if (!is_disposed) {
384389
templates_quick_pick.show()
385390
}

0 commit comments

Comments
 (0)