diff --git a/frontend/src/components/settings/KeyboardShortcuts.tsx b/frontend/src/components/settings/KeyboardShortcuts.tsx index d15fb042..6c43f0f9 100644 --- a/frontend/src/components/settings/KeyboardShortcuts.tsx +++ b/frontend/src/components/settings/KeyboardShortcuts.tsx @@ -8,7 +8,7 @@ import { formatEventModifiers, formatShortcutEvent, isModifierOnlyEvent, normali import { applyTuiKeybindImport, parseTuiKeybindConfig } from '@/lib/tuiKeybindImport' import { showToast } from '@/lib/toast' -const CONVERSATION_ACTIONS = ['submit', 'abort', 'clearPrompt', 'toggleMode', 'undo', 'redo', 'compact', 'fork', 'timeline', 'exportSession', 'selectModel', 'variantCycle'] +const CONVERSATION_ACTIONS = ['submit', 'abort', 'clearPrompt', 'toggleMode', 'undo', 'redo', 'compact', 'fork', 'timeline', 'exportSession', 'selectModel', 'variantCycle', 'halfPageUp', 'halfPageDown'] const NAVIGATION_ACTIONS = ['settings', 'sessions', 'newSession', 'closeSession', 'toggleSidebar', 'toggleTerminal', 'toggleSourceControl'] const formatShortcutLabel = (action: string): string => { diff --git a/frontend/src/contexts/KeyboardShortcutsContext.test.tsx b/frontend/src/contexts/KeyboardShortcutsContext.test.tsx index 1738d48e..cd66a203 100644 --- a/frontend/src/contexts/KeyboardShortcutsContext.test.tsx +++ b/frontend/src/contexts/KeyboardShortcutsContext.test.tsx @@ -186,6 +186,18 @@ describe('KeyboardShortcutsProvider', () => { } }) + it('runs a direct half-page-down shortcut with Ctrl+D from the body and the prompt', () => { + const halfPageDown = vi.fn() + renderProvider() + const prompt = mountElement('textarea', { 'data-prompt-input': '' }) + + expect(pressKey(document.body, { key: 'd', ctrlKey: true }).defaultPrevented).toBe(true) + expect(halfPageDown).toHaveBeenCalledTimes(1) + + expect(pressKey(prompt, { key: 'd', ctrlKey: true }).defaultPrevented).toBe(true) + expect(halfPageDown).toHaveBeenCalledTimes(2) + }) + it('runs leader and direct shortcuts from a terminal before it consumes the keys, passing other keys through', () => { const newSession = vi.fn() const toggleTerminal = vi.fn() diff --git a/frontend/src/lib/tuiKeybindImport.ts b/frontend/src/lib/tuiKeybindImport.ts index 85f8ce15..eb8b8d92 100644 --- a/frontend/src/lib/tuiKeybindImport.ts +++ b/frontend/src/lib/tuiKeybindImport.ts @@ -48,6 +48,8 @@ const ACTION_BY_TUI_NAME = new Map([ ['diff.open', 'toggleSourceControl'], ['session.timeline', 'timeline'], ['session.export', 'exportSession'], + ['session.half.page.up', 'halfPageUp'], + ['session.half.page.down', 'halfPageDown'], ]) const ACTION_BY_LEGACY_NAME = new Map([ @@ -67,6 +69,8 @@ const ACTION_BY_LEGACY_NAME = new Map([ ['diff_open', 'toggleSourceControl'], ['session_timeline', 'timeline'], ['session_export', 'exportSession'], + ['messages_half_page_up', 'halfPageUp'], + ['messages_half_page_down', 'halfPageDown'], ]) const MODIFIER_LABELS = new Map([ diff --git a/frontend/src/pages/SessionDetail.tsx b/frontend/src/pages/SessionDetail.tsx index 93f0226b..004ca443 100644 --- a/frontend/src/pages/SessionDetail.tsx +++ b/frontend/src/pages/SessionDetail.tsx @@ -587,6 +587,12 @@ export function SessionDetail() { promptInputRef.current?.clearPrompt() }, []); + const scrollMessagesByHalfPage = useCallback((direction: 1 | -1) => { + const container = messageContainerRef.current; + if (!container) return; + container.scrollBy({ top: direction * container.clientHeight / 2 }); + }, []); + useShortcutActions({ selectModel: handleOpenModelDialog, sessions: handleShowSessionsDialog, @@ -603,6 +609,8 @@ export function SessionDetail() { submit: () => document.querySelector("[data-submit-prompt]")?.click(), abort: isSessionActive ? handleInterruptSession : undefined, clearPrompt: handleClearPrompt, + halfPageUp: () => scrollMessagesByHalfPage(-1), + halfPageDown: () => scrollMessagesByHalfPage(1), }); const handleUndoMessage = useCallback((restoredPrompt: string) => { diff --git a/shared/src/schemas/settings.ts b/shared/src/schemas/settings.ts index 104aeff3..919de9a2 100644 --- a/shared/src/schemas/settings.ts +++ b/shared/src/schemas/settings.ts @@ -89,11 +89,13 @@ export const DEFAULT_KEYBOARD_SHORTCUTS = { toggleSourceControl: 'D', timeline: 'G', exportSession: 'X', + halfPageUp: 'Ctrl+U', + halfPageDown: 'Ctrl+D', } satisfies Record; export type KeyboardShortcutAction = keyof typeof DEFAULT_KEYBOARD_SHORTCUTS; -export const DEFAULT_DIRECT_SHORTCUTS = ['submit', 'abort', 'clearPrompt', 'variantCycle', 'toggleTerminal']; +export const DEFAULT_DIRECT_SHORTCUTS = ['submit', 'abort', 'clearPrompt', 'variantCycle', 'toggleTerminal', 'halfPageUp', 'halfPageDown']; export const GitCredentialSchema = z.object({ id: z.string().optional(),