Files
kandev/apps/web/lib/keyboard/shortcut-overrides.ts
T
João Salavisa 85a1333dec feat(web): make chat reverse-i-search shortcut configurable (#1255)
* feat(web): make chat reverse-i-search shortcut configurable

Ctrl+R was hardcoded in the TipTap ProseMirror plugin and could not be
rebound from Settings → Shortcuts. Register REVERSE_SEARCH in the
shared shortcut registry and resolve the binding through the user
overrides ref so the Settings UI exposes it like every other shortcut.

Default stays Ctrl+R (plain Ctrl, not ctrlOrCmd) so Cmd+R on macOS
keeps reloading the browser tab.

* test(web): cover REVERSE_SEARCH in shortcut-overrides tests

Bump toHaveLength(12) → toHaveLength(13), add toContain check, and
add the label/default assertion in the "each entry" block. Without
this, CI fails on the configurable-shortcut count assertion.

---------

Co-authored-by: Kandev Agent <agent@kandev.dev>
2026-06-02 23:06:11 +01:00

64 lines
2.3 KiB
TypeScript

import { SHORTCUTS, type KeyboardShortcut } from "./constants";
export type ConfigurableShortcutId =
| "SEARCH"
| "FILE_SEARCH"
| "QUICK_CHAT"
| "BOTTOM_TERMINAL"
| "TOGGLE_SIDEBAR"
| "COMMAND_PANEL"
| "NEW_TASK"
| "FOCUS_INPUT"
| "TOGGLE_PLAN_MODE"
| "TASK_SWITCHER"
| "TASK_SWITCHER_REVERSE"
| "VOICE_INPUT_TOGGLE"
| "REVERSE_SEARCH";
export type StoredShortcutOverrides = Record<
string,
{ key: string; modifiers?: Record<string, boolean> }
>;
export const CONFIGURABLE_SHORTCUTS: Record<
ConfigurableShortcutId,
{ label: string; default: KeyboardShortcut }
> = {
SEARCH: { label: "Command Panel", default: SHORTCUTS.SEARCH },
FILE_SEARCH: { label: "File Search", default: SHORTCUTS.FILE_SEARCH },
QUICK_CHAT: { label: "Quick Chat", default: SHORTCUTS.QUICK_CHAT },
BOTTOM_TERMINAL: { label: "Toggle Bottom Terminal", default: SHORTCUTS.BOTTOM_TERMINAL },
TOGGLE_SIDEBAR: { label: "Toggle Sidebar", default: SHORTCUTS.TOGGLE_SIDEBAR },
COMMAND_PANEL: { label: "Command Panel (Alt)", default: SHORTCUTS.COMMAND_PANEL },
NEW_TASK: { label: "New Task", default: SHORTCUTS.NEW_TASK },
FOCUS_INPUT: { label: "Focus Chat Input", default: SHORTCUTS.FOCUS_INPUT },
TOGGLE_PLAN_MODE: { label: "Toggle Plan Mode", default: SHORTCUTS.TOGGLE_PLAN_MODE },
TASK_SWITCHER: { label: "Recent Task Switcher", default: SHORTCUTS.TASK_SWITCHER },
TASK_SWITCHER_REVERSE: {
label: "Recent Task Switcher (Backward)",
default: SHORTCUTS.TASK_SWITCHER_REVERSE,
},
VOICE_INPUT_TOGGLE: { label: "Voice Input", default: SHORTCUTS.VOICE_INPUT_TOGGLE },
REVERSE_SEARCH: { label: "Reverse Chat Search", default: SHORTCUTS.REVERSE_SEARCH },
};
export function getShortcut(
id: ConfigurableShortcutId,
overrides?: StoredShortcutOverrides,
): KeyboardShortcut {
const override = overrides?.[id];
if (override) return override as KeyboardShortcut;
return CONFIGURABLE_SHORTCUTS[id].default;
}
export function resolveAllShortcuts(
overrides?: StoredShortcutOverrides,
): Record<ConfigurableShortcutId, KeyboardShortcut> {
const ids = Object.keys(CONFIGURABLE_SHORTCUTS) as ConfigurableShortcutId[];
const result = {} as Record<ConfigurableShortcutId, KeyboardShortcut>;
for (const id of ids) {
result[id] = getShortcut(id, overrides);
}
return result;
}