Skip to content

Commit 7e3ff18

Browse files
committed
Add Ctrl/Cmd+1-9 shortcuts to switch or create prompt tabs
- allow cycling through tabs with cmd+1 cmd+2 etc - if there are 3 tabs, doing cmd+4 should open fourth one. When there are 5 tabs, doing cmd+6 shoul dopen seventh one. ├── apps │ └── editor │ └── src │ └── views │ └── prompt │ └── frontend │ └── Main │ └── MainView │ └── MainView.tsx └── packages └── ui └── src └── components └── editor └── common └── prompts └── PromptField ├── PromptField.module.scss ├── PromptField.stories.tsx ├── PromptField.tsx ├── components │ ├── CompletedTasks │ │ ├── CompletedTasks.module.scss │ │ ├── CompletedTasks.tsx │ │ └── index.ts │ ├── Footer │ │ ├── Footer.module.scss │ │ ├── Footer.tsx │ │ └── index.ts │ └── Tabs │ ├── Tabs.module.scss │ ├── Tabs.tsx │ └── index.ts ├── hooks │ ├── use-drag-drop.ts │ ├── use-dropdown.ts │ ├── use-ghost-text.ts │ ├── use-handlers │ │ ├── handle-copy.ts │ │ ├── handle-cut.ts │ │ ├── handle-input-change.ts │ │ ├── handle-input-click.ts │ │ ├── handle-key-down.ts │ │ ├── handle-paste.ts │ │ ├── handle-submit.ts │ │ ├── index.ts │ │ ├── types.ts │ │ ├── use-handlers.ts │ │ └── utils.ts │ └── use-keyboard-shortcuts.ts └── index.ts
1 parent 0b80669 commit 7e3ff18

1 file changed

Lines changed: 19 additions & 0 deletions

File tree

‎packages/ui/src/components/editor/common/prompts/PromptField/hooks/use-keyboard-shortcuts.ts‎

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -139,6 +139,25 @@ export const use_keyboard_shortcuts = (props: PromptField.Props) => {
139139
e: React.KeyboardEvent<HTMLDivElement>
140140
) => {
141141
if (props.are_keyboard_shortcuts_disabled) return
142+
143+
if ((e.ctrlKey || e.metaKey) && !e.shiftKey && !e.altKey) {
144+
const match = e.key.match(/^[1-9]$/)
145+
if (match) {
146+
const index = parseInt(match[0], 10) - 1
147+
if (index < props.tabs_count) {
148+
e.preventDefault()
149+
e.stopPropagation()
150+
props.on_tab_change(index)
151+
return
152+
} else if (index == props.tabs_count) {
153+
e.preventDefault()
154+
e.stopPropagation()
155+
props.on_new_tab()
156+
return
157+
}
158+
}
159+
}
160+
142161
if (e.key == 'Escape' && !e.ctrlKey && !e.metaKey && !e.altKey) {
143162
if (props.is_recording) {
144163
props.on_recording_finished()

0 commit comments

Comments
 (0)