Skip to content

Commit 7985c20

Browse files
authored
fix(app): show keybind tooltips on prompt input controls (anomalyco#37824)
1 parent 67caf89 commit 7985c20

3 files changed

Lines changed: 54 additions & 39 deletions

File tree

packages/app/src/components/prompt-input-v2.tsx

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,8 @@ export function PromptInputV2Composer(props: PromptInputV2ComposerProps) {
6060
controller={props.controller}
6161
borderUnderlay={props.borderUnderlay}
6262
class={props.class}
63+
attachKeybind={command.keybindParts("file.attach")}
64+
attachShortcut={command.keybind("file.attach")}
6365
modelControl={
6466
<PromptInputV2ModelControl
6567
loading={props.controller.model.loading}
@@ -451,12 +453,14 @@ export function usePromptInputV2Controller(props: PromptInputV2ControllerProps):
451453
options: () => props.controls.agents.options.map((name) => ({ id: name, label: name })),
452454
current: () => props.controls.agents.current,
453455
onSelect: props.controls.agents.select,
456+
keybind: () => command.keybindParts("agent.cycle"),
454457
}
455458
: undefined,
456459
variant: {
457460
options: () => variants().map((value) => ({ id: value, label: value })),
458461
current: () => props.controls.model.selection.variant.current() ?? "default",
459462
onSelect: (value) => props.controls.model.selection.variant.set(value === "default" ? undefined : value),
463+
keybind: () => command.keybindParts("model.variant.cycle"),
460464
},
461465
submit: {
462466
stopping,

packages/session-ui/src/v2/components/prompt-input/index.tsx

Lines changed: 49 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,8 @@ export type PromptInputV2Props = {
3939
borderUnderlay?: boolean
4040
class?: string
4141
modelControl?: JSX.Element
42+
attachKeybind?: string[]
43+
attachShortcut?: string
4244
}
4345

4446
export function PromptInputV2(props: PromptInputV2Props) {
@@ -197,9 +199,9 @@ export function PromptInputV2(props: PromptInputV2Props) {
197199
<PromptInputV2AddMenu
198200
disabled={state.mode === "shell"}
199201
title="Add images and files"
200-
keybind={["Mod", "U"]}
202+
keybind={props.attachKeybind ?? ["Mod", "U"]}
201203
attachLabel="Images and files"
202-
attachShortcut="Mod+U"
204+
attachShortcut={props.attachShortcut ?? "Mod+U"}
203205
commandsLabel="Commands"
204206
contextLabel="Context"
205207
shellLabel="Shell command"
@@ -233,7 +235,11 @@ export function PromptInputV2(props: PromptInputV2Props) {
233235
<Show when={view.variant}>
234236
{(control) => (
235237
<Show when={control().options().length > 1}>
236-
<PromptInputV2ConfiguredSelect title="Choose model variant" control={control()} />
238+
<PromptInputV2ConfiguredSelect
239+
title="Choose model variant"
240+
keybind={["Shift", "Mod", "D"]}
241+
control={control()}
242+
/>
237243
</Show>
238244
)}
239245
</Show>
@@ -512,7 +518,7 @@ function PromptInputV2ConfiguredSelect(props: {
512518
return (
513519
<PromptInputV2Select
514520
title={props.title}
515-
keybind={props.keybind}
521+
keybind={props.control.keybind?.() ?? props.keybind}
516522
options={props.control.options()}
517523
current={current()}
518524
currentIcon={
@@ -536,36 +542,45 @@ export function PromptInputV2Select(props: {
536542
onSelect: (id: string) => void
537543
}) {
538544
return (
539-
<MenuV2 gutter={6} modal={false} placement="top-start" onOpenChange={props.onOpenChange}>
540-
<MenuV2.Trigger
541-
as={ButtonV2}
542-
variant="ghost-muted"
543-
size="normal"
544-
class={`max-w-[220px] justify-start ![font-weight:440] ${props.class ?? ""}`}
545-
title={keybindTitle(props.title, props.keybind)}
546-
>
547-
{props.currentIcon}
548-
<span class="truncate capitalize leading-5">
549-
{props.options.find((option) => option.id === props.current)?.label ?? props.current}
550-
</span>
551-
<span class="-ml-0.5 -mr-1 flex shrink-0">
552-
<IconV2 name="chevron-down" />
553-
</span>
554-
</MenuV2.Trigger>
555-
<MenuV2.Portal>
556-
<MenuV2.Content>
557-
<MenuV2.RadioGroup value={props.current} onChange={props.onSelect}>
558-
<For each={props.options}>
559-
{(option) => (
560-
<MenuV2.RadioItem value={option.id} class="capitalize" closeOnSelect>
561-
{option.label}
562-
</MenuV2.RadioItem>
563-
)}
564-
</For>
565-
</MenuV2.RadioGroup>
566-
</MenuV2.Content>
567-
</MenuV2.Portal>
568-
</MenuV2>
545+
<TooltipV2
546+
placement="top"
547+
value={
548+
<>
549+
{props.title}
550+
<KeybindV2 keys={props.keybind ?? []} variant="neutral" />
551+
</>
552+
}
553+
>
554+
<MenuV2 gutter={6} modal={false} placement="top-start" onOpenChange={props.onOpenChange}>
555+
<MenuV2.Trigger
556+
as={ButtonV2}
557+
variant="ghost-muted"
558+
size="normal"
559+
class={`max-w-[220px] justify-start ![font-weight:440] ${props.class ?? ""}`}
560+
>
561+
{props.currentIcon}
562+
<span class="truncate capitalize leading-5">
563+
{props.options.find((option) => option.id === props.current)?.label ?? props.current}
564+
</span>
565+
<span class="-ml-0.5 -mr-1 flex shrink-0">
566+
<IconV2 name="chevron-down" />
567+
</span>
568+
</MenuV2.Trigger>
569+
<MenuV2.Portal>
570+
<MenuV2.Content>
571+
<MenuV2.RadioGroup value={props.current} onChange={props.onSelect}>
572+
<For each={props.options}>
573+
{(option) => (
574+
<MenuV2.RadioItem value={option.id} class="capitalize" closeOnSelect>
575+
{option.label}
576+
</MenuV2.RadioItem>
577+
)}
578+
</For>
579+
</MenuV2.RadioGroup>
580+
</MenuV2.Content>
581+
</MenuV2.Portal>
582+
</MenuV2>
583+
</TooltipV2>
569584
)
570585
}
571586

@@ -688,8 +703,3 @@ function PromptInputV2SuggestionIcon(props: { item: PromptInputV2Suggestion }) {
688703
/>
689704
)
690705
}
691-
692-
function keybindTitle(label: string, keybind?: string[]) {
693-
if (!keybind?.length) return label
694-
return `${label} (${keybind.join("+")})`
695-
}

packages/session-ui/src/v2/components/prompt-input/interaction.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ export type PromptInputV2SelectControl = {
2323
options: Accessor<PromptInputV2Option[]>
2424
current: Accessor<string>
2525
onSelect: (id: string) => void
26+
keybind?: Accessor<string[]>
2627
}
2728

2829
export type PromptInputV2ViewConfig = {

0 commit comments

Comments
 (0)