feat(shortcuts): add half-page message scroll shortcuts

This commit is contained in:
Chris Scott committed 2026-10-08 11:50:37 -04:00
1 parent b06de60f6b
commit 7e8443f54f
5 files changed
+28 -2

No files matched your search

@@ -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 => {
@@ -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(<ActionLayer actions={{ halfPageDown }} />)
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()
+4
View File
@@ -48,6 +48,8 @@ const ACTION_BY_TUI_NAME = new Map<string, KeyboardShortcutAction>([
['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<string, KeyboardShortcutAction>([
@@ -67,6 +69,8 @@ const ACTION_BY_LEGACY_NAME = new Map<string, KeyboardShortcutAction>([
['diff_open', 'toggleSourceControl'],
['session_timeline', 'timeline'],
['session_export', 'exportSession'],
['messages_half_page_up', 'halfPageUp'],
['messages_half_page_down', 'halfPageDown'],
])
const MODIFIER_LABELS = new Map<string, string | null>([
+8
View File
@@ -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<HTMLButtonElement>("[data-submit-prompt]")?.click(),
abort: isSessionActive ? handleInterruptSession : undefined,
clearPrompt: handleClearPrompt,
halfPageUp: () => scrollMessagesByHalfPage(-1),
halfPageDown: () => scrollMessagesByHalfPage(1),
});
const handleUndoMessage = useCallback((restoredPrompt: string) => {
+3 -1
View File
@@ -89,11 +89,13 @@ export const DEFAULT_KEYBOARD_SHORTCUTS = {
toggleSourceControl: 'D',
timeline: 'G',
exportSession: 'X',
halfPageUp: 'Ctrl+U',
halfPageDown: 'Ctrl+D',
} satisfies Record<string, string>;
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(),