Skip to content

Self-hosted, Self-Improving, Federated Everything App — dev management, agent orchestration, persistent mind, digital twin, second brain, and creative pipeline from a single dashboard over Tailscale to port the user into the OS

fix: drop key auto-repeat and suppress card shortcuts behind open modals (#1603)

[._.]/ Adam Eivy69b0f6c26ff9
diff --git a/client/src/components/pipeline/manuscript/ManuscriptCommentCard.jsx b/client/src/components/pipeline/manuscript/ManuscriptCommentCard.jsx
index b9861d8249..7fe10a8e0d 100644
--- a/client/src/components/pipeline/manuscript/ManuscriptCommentCard.jsx
+++ b/client/src/components/pipeline/manuscript/ManuscriptCommentCard.jsx
@@ -208,8 +208,11 @@ export default function ManuscriptCommentCard({
// Keyboard-driven triage over the open note (#1603): ←/→ (or k/j, vim-style)
// step prev/next through the triage order, a=accept, d=dismiss, g=generate/
// regenerate. Only one comment card mounts at a time (the open note), so the
- // single global binding here can't collide. The hook ignores keys typed into
- // the replacement textarea / manuscript editor, so letters never misfire.
+ // single global binding can't collide with a sibling card. The hook ignores
+ // keys typed into the replacement textarea / manuscript editor, drops OS key
+ // auto-repeat (so a held a/d can't stampede through auto-advancing notes), and
+ // suppresses itself while a manuscript modal (Impact preview / Read aloud) is
+ // open over the still-mounted card — so letters never misfire.
useKeyboardShortcuts(true, {
ArrowLeft: nav?.onPrev,
ArrowRight: nav?.onNext,
diff --git a/client/src/hooks/README.md b/client/src/hooks/README.md
index f940931f25..704edbf940 100644
--- a/client/src/hooks/README.md
+++ b/client/src/hooks/README.md
@@ -90,7 +90,7 @@ grep -i "what you want to do" client/src/hooks/README.md
| `useRowDraft` | Multi-column row draft (analogue of `useFieldDraft`). | Multi-column row that commits as a unit. |
| `usePendingListRows` | List-of-rows where a new row is held client-side until a required column fills, then promoted to `onChange`. | Editable list whose nameless rows would otherwise be dropped by the server sanitizer (WardrobeSection, CharacterDetailEditor list sections). |
| `useKeyboardControls` | Keyboard binding for CyberCity mode toggle. | CyberCity-specific. |
-| `useKeyboardShortcuts` | `useKeyboardShortcuts(active, bindings)` — fire a `{ key: handler }` map while `active`; ignores events from editable fields (`isEditableTarget` also exported) and ⌘/Ctrl/Alt chords; a falsy handler disables that key. | Single-surface action shortcuts (editorial comment card prev/next + accept/dismiss/generate, #1603). Not for held-key/game input (that's `useKeyboardControls`). |
+| `useKeyboardShortcuts` | `useKeyboardShortcuts(active, bindings, opts?)` — fire a `{ key: handler }` map while `active`; ignores events from editable fields (`isEditableTarget` also exported), ⌘/Ctrl/Alt chords, OS key auto-repeat (`{ ignoreRepeat: false }` to opt back in), and any keystroke while an `aria-modal` dialog is open (`{ enabledInDialog: true }` for a modal-owned shortcut); a falsy handler disables that key. | Single-surface action shortcuts (editorial comment card prev/next + accept/dismiss/generate, #1603). Not for held-key/game input (that's `useKeyboardControls`). |
| `useKeyboardHelp` | Esc closes, even from inputs/textareas. | Help/cheatsheet modals. |
| `useLockToggle` | Optimistic-PATCH lock toggle. | New "lock this field/stage/arc" button — use this, do not re-implement. |
| `usePopoverPosition` | Viewport-clamped `{ left, top, width }` for a fixed-position portal popover anchored to a trigger; re-measures on open and rAF-coalesced on capture-phase scroll/resize. Returns `{ triggerRef, popoverRef, style, reposition }`; pass `anchorRef` to follow a parent-owned trigger. | Any portal-into-`<body>` menu/popover placed relative to a button (ThemeSwitcher, CollectionPickerShell) — use this instead of re-rolling the measure/flip/clamp/reflow plumbing. |
diff --git a/client/src/hooks/useKeyboardShortcuts.js b/client/src/hooks/useKeyboardShortcuts.js
index 909b1e514b..5bcb4c214c 100644
--- a/client/src/hooks/useKeyboardShortcuts.js
+++ b/client/src/hooks/useKeyboardShortcuts.js
@@ -18,18 +18,29 @@ export function isEditableTarget(el) {
* and any ⌘/Ctrl/Alt chord is skipped so app/browser shortcuts still win. The
* event is `preventDefault`-ed only when a binding actually matches.
*
+ * Two guards keep these page-level shortcuts from misfiring:
+ * - **Auto-repeat is dropped** (`e.repeat`) so a held key fires once, not once
+ * per OS repeat tick — a long press on a one-shot action (accept/dismiss, which
+ * may auto-advance to the next item) must not stampede through several of them.
+ * - **An open modal suppresses them**: while any `aria-modal` dialog is mounted
+ * it owns the top surface, so a bare `a`/`d` typed into that modal must not
+ * reach a page-level card still mounted behind it. Pass `{ enabledInDialog:
+ * true }` for a shortcut that genuinely lives inside a modal.
+ *
* Bindings are read through a ref, so handlers recreated every render don't
* re-subscribe the listener — only `active` does. The listener detaches while
* inactive, so a closed card/popover keeps no global keydown handler around.
*/
-export default function useKeyboardShortcuts(active, bindings) {
+export default function useKeyboardShortcuts(active, bindings, { ignoreRepeat = true, enabledInDialog = false } = {}) {
const bindingsRef = useRef(bindings);
bindingsRef.current = bindings;
useEffect(() => {
if (!active) return undefined;
const onKey = (e) => {
if (e.metaKey || e.ctrlKey || e.altKey) return;
+ if (ignoreRepeat && e.repeat) return;
if (isEditableTarget(e.target)) return;
+ if (!enabledInDialog && document.querySelector('[aria-modal="true"]')) return;
const handler = bindingsRef.current[e.key];
if (typeof handler !== 'function') return;
e.preventDefault();
@@ -37,5 +48,5 @@ export default function useKeyboardShortcuts(active, bindings) {
};
window.addEventListener('keydown', onKey);
return () => window.removeEventListener('keydown', onKey);
- }, [active]);
+ }, [active, ignoreRepeat, enabledInDialog]);
}
diff --git a/client/src/hooks/useKeyboardShortcuts.test.jsx b/client/src/hooks/useKeyboardShortcuts.test.jsx
index a22d46821d..81a8b7bd33 100644
--- a/client/src/hooks/useKeyboardShortcuts.test.jsx
+++ b/client/src/hooks/useKeyboardShortcuts.test.jsx
@@ -89,6 +89,39 @@ describe('useKeyboardShortcuts', () => {
expect(addSpy.mock.calls.filter(([type]) => type === 'keydown').length).toBe(keydownSubs);
});
+ it('ignores OS key auto-repeat so a held one-shot key fires once, not per tick', () => {
+ const d = vi.fn();
+ renderHook(() => useKeyboardShortcuts(true, { d }));
+ fireEvent.keyDown(window, { key: 'd', repeat: true });
+ expect(d).not.toHaveBeenCalled();
+ fireEvent.keyDown(window, { key: 'd' });
+ expect(d).toHaveBeenCalledTimes(1);
+ });
+
+ it('suppresses shortcuts while an aria-modal dialog is open (page card stays behind it)', () => {
+ const d = vi.fn();
+ renderHook(() => useKeyboardShortcuts(true, { d }));
+ const dialog = document.createElement('div');
+ dialog.setAttribute('aria-modal', 'true');
+ document.body.appendChild(dialog);
+ press('d');
+ expect(d).not.toHaveBeenCalled();
+ document.body.removeChild(dialog);
+ press('d');
+ expect(d).toHaveBeenCalledTimes(1);
+ });
+
+ it('enabledInDialog lets a modal-owned shortcut fire even with an open dialog', () => {
+ const d = vi.fn();
+ renderHook(() => useKeyboardShortcuts(true, { d }, { enabledInDialog: true }));
+ const dialog = document.createElement('div');
+ dialog.setAttribute('aria-modal', 'true');
+ document.body.appendChild(dialog);
+ press('d');
+ document.body.removeChild(dialog);
+ expect(d).toHaveBeenCalledTimes(1);
+ });
+
it('detaches the listener on unmount', () => {
const a = vi.fn();
const { unmount } = renderHook(() => useKeyboardShortcuts(true, { a }));