Skip to content

Commit 1b2790f

Browse files
committed
Add alt slash keyboard shortcut for agentic search with status bar keycap support
- trigger 'agentic search' on keyboard shortcut 'alt /', display keycap on top of the action in the statusbar ├── apps │ └── editor │ └── src │ └── views │ └── prompt │ └── frontend │ ├── Main │ │ ├── Main.tsx │ │ └── MainView │ │ ├── MainView.tsx │ │ ├── components │ │ │ ├── BrowserConnectionStatus │ │ │ │ └── BrowserConnectionStatus.tsx │ │ │ ├── Header │ │ │ │ ├── Header.module.scss │ │ │ │ ├── Header.tsx │ │ │ │ └── index.ts │ │ │ └── PromptAttachments │ │ │ └── PromptAttachments.tsx │ │ └── hooks │ │ └── use-keyboard-shortcuts.ts │ └── Prompt.tsx └── packages └── ui └── src └── components └── editor └── prompt ├── ResponsePreview │ └── components │ └── FileItem │ └── FileItem.tsx └── StatusBar └── StatusBar.tsx
1 parent 8941677 commit 1b2790f

5 files changed

Lines changed: 50 additions & 24 deletions

File tree

‎apps/editor/src/views/prompt/frontend/Main/MainView/MainView.tsx‎

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ import { Scrollable as UiScrollable } from '@ui/components/editor/common/Scrolla
1414
import { BrowserConnectionStatus } from './components/BrowserConnectionStatus'
1515
import { ApiConfiguration } from '@/views/prompt/types/messages'
1616
import { use_last_choice_tooltip } from './hooks/use-last-choice-tooltip'
17+
import { use_keyboard_shortcuts } from './hooks/use-keyboard-shortcuts'
1718
import { Header } from './components/Header'
1819
import { SelectionState } from '@/views/prompt/types/messages'
1920
import { use_translation } from '../../i18n/use-translation'
@@ -187,6 +188,15 @@ export const MainView: React.FC<Props> = (props) => {
187188
api_configurations: props.api_configurations
188189
})
189190

191+
const { is_alt_pressed } = use_keyboard_shortcuts({
192+
target: props.target,
193+
on_web_prompt_type_change: props.on_web_prompt_type_change,
194+
on_api_prompt_type_change: props.on_api_prompt_type_change,
195+
on_show_home: props.on_show_home,
196+
on_agentic_search: props.on_agentic_search,
197+
is_disabled: props.are_keyboard_shortcuts_disabled
198+
})
199+
190200
const web_configurations: UiConfigurations.Configuration[] =
191201
props.web_configurations.map((web_configuration, index) => {
192202
const is_unnamed =
@@ -253,7 +263,7 @@ export const MainView: React.FC<Props> = (props) => {
253263
on_web_prompt_type_change={props.on_web_prompt_type_change}
254264
api_prompt_type={props.api_prompt_type}
255265
on_api_prompt_type_change={props.on_api_prompt_type_change}
256-
are_keyboard_shortcuts_disabled={props.are_keyboard_shortcuts_disabled}
266+
is_alt_pressed={is_alt_pressed}
257267
/>
258268
<UiScrollable scroll_to_top_key={props.scroll_reset_key} top_shadow>
259269
<UiSeparator height={2} />
@@ -433,6 +443,7 @@ export const MainView: React.FC<Props> = (props) => {
433443
? 'blue'
434444
: 'purple'
435445
}
446+
is_alt_pressed={is_alt_pressed}
436447
on_agentic_search={props.on_agentic_search}
437448
translations={{
438449
attaching_file: t('selected-files.attaching-file'),

‎apps/editor/src/views/prompt/frontend/Main/MainView/components/Header/Header.tsx‎

Lines changed: 3 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@ import {
99
api_prompt_type_labels,
1010
web_prompt_type_labels
1111
} from '../../prompt-type-labels'
12-
import { use_keyboard_shortcuts } from './hooks/use-keyboard-shortcuts'
1312
import { use_translation } from '@/views/prompt/frontend/i18n/use-translation'
1413

1514
type Props = {
@@ -19,21 +18,13 @@ type Props = {
1918
api_prompt_type: ApiPromptType
2019
on_web_prompt_type_change: (prompt_type: WebPromptType) => void
2120
on_api_prompt_type_change: (prompt_type: ApiPromptType) => void
22-
are_keyboard_shortcuts_disabled: boolean
21+
is_alt_pressed: boolean
2322
}
2423

2524
export const Header: React.FC<Props> = (props) => {
2625
const { t } = use_translation()
2726
const { container_ref, compact_step } = use_compacting()
2827

29-
const { is_alt_pressed } = use_keyboard_shortcuts({
30-
target: props.target,
31-
on_web_prompt_type_change: props.on_web_prompt_type_change,
32-
on_api_prompt_type_change: props.on_api_prompt_type_change,
33-
on_show_home: props.on_show_home,
34-
is_disabled: props.are_keyboard_shortcuts_disabled
35-
})
36-
3728
return (
3829
<div className={styles.header} ref={container_ref}>
3930
<div className={styles.header__left}>
@@ -44,7 +35,7 @@ export const Header: React.FC<Props> = (props) => {
4435
/>
4536
{props.target == TARGET.WEB && (
4637
<>
47-
<UiKeycapWrapper char={is_alt_pressed ? 'E' : undefined}>
38+
<UiKeycapWrapper char={props.is_alt_pressed ? 'E' : undefined}>
4839
<UiIconAccentButton
4940
label={web_prompt_type_labels['edit-files']}
5041
icon="edit-sparkle"
@@ -58,7 +49,7 @@ export const Header: React.FC<Props> = (props) => {
5849
on_click={() => props.on_web_prompt_type_change('edit-files')}
5950
/>
6051
</UiKeycapWrapper>
61-
<UiKeycapWrapper char={is_alt_pressed ? 'A' : undefined}>
52+
<UiKeycapWrapper char={props.is_alt_pressed ? 'A' : undefined}>
6253
<UiIconAccentButton
6354
label={web_prompt_type_labels['ask-about-files']}
6455
icon="chat-sparkle"

‎apps/editor/src/views/prompt/frontend/Main/MainView/components/PromptAttachments/PromptAttachments.tsx‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ type Props = {
1111
attaching_files: string
1212
agentic_search: string
1313
}
14+
is_alt_pressed?: boolean
1415
on_agentic_search: () => void
1516
}
1617

@@ -37,6 +38,7 @@ export const PromptAttachments: React.FC<Props> = (props) => {
3738
id: 'agentic-search',
3839
icon: 'codicon-search-sparkle',
3940
label: props.translations.agentic_search,
41+
keycap: props.is_alt_pressed ? '/' : undefined,
4042
on_click: props.on_agentic_search
4143
}
4244
]}

apps/editor/src/views/prompt/frontend/Main/MainView/components/Header/hooks/use-keyboard-shortcuts.ts renamed to apps/editor/src/views/prompt/frontend/Main/MainView/hooks/use-keyboard-shortcuts.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ export const use_keyboard_shortcuts = (params: {
77
on_web_prompt_type_change: (prompt_type: WebPromptType) => void
88
on_api_prompt_type_change: (prompt_type: ApiPromptType) => void
99
on_show_home: () => void
10+
on_agentic_search?: () => void
1011
is_disabled: boolean
1112
}) => {
1213
const [is_alt_pressed, set_is_alt_pressed] = useState(false)
@@ -132,6 +133,12 @@ export const use_keyboard_shortcuts = (params: {
132133
params.on_web_prompt_type_change('ask-about-files')
133134
return
134135
}
136+
137+
if (event.code == 'Slash' || event.key == '/') {
138+
event.preventDefault()
139+
params.on_agentic_search?.()
140+
return
141+
}
135142
}
136143

137144
window.addEventListener('keydown', handle_key_down)
@@ -143,6 +150,7 @@ export const use_keyboard_shortcuts = (params: {
143150
params.target,
144151
params.on_web_prompt_type_change,
145152
params.on_api_prompt_type_change,
153+
params.on_agentic_search,
146154
params.is_disabled
147155
])
148156

‎packages/ui/src/components/editor/prompt/StatusBar/StatusBar.tsx‎

Lines changed: 25 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,14 @@
11
import React from 'react'
22
import cn from 'classnames'
33
import styles from './StatusBar.module.scss'
4+
import { KeycapWrapper } from '../KeycapWrapper'
45

56
export type StatusBarAction = {
67
id: string
78
icon: string
89
label?: string
910
title?: string
11+
keycap?: string
1012
on_click: (e: React.MouseEvent) => void
1113
}
1214

@@ -57,17 +59,29 @@ export const StatusBar: React.FC<Props> = ({
5759
</div>
5860
{actions && actions.length > 0 && (
5961
<div className={styles.actions}>
60-
{actions.map((action) => (
61-
<div
62-
key={action.id}
63-
className={styles.action}
64-
onClick={action.on_click}
65-
title={action.title}
66-
>
67-
<span className={cn('codicon', action.icon)} />
68-
{action.label && <span>{action.label}</span>}
69-
</div>
70-
))}
62+
{actions.map((action) => {
63+
const content = (
64+
<div
65+
key={action.id}
66+
className={styles.action}
67+
onClick={action.on_click}
68+
title={action.title}
69+
>
70+
<span className={cn('codicon', action.icon)} />
71+
{action.label && <span>{action.label}</span>}
72+
</div>
73+
)
74+
75+
if (action.keycap) {
76+
return (
77+
<KeycapWrapper key={action.id} char={action.keycap}>
78+
{content}
79+
</KeycapWrapper>
80+
)
81+
}
82+
83+
return content
84+
})}
7185
</div>
7286
)}
7387
</div>

0 commit comments

Comments
 (0)