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

refactor: extract shared ui/Kbd keycap and reuse isEditableTarget (#1603)

[._.]/ Adam Eivyfb1dc5fde82c
diff --git a/.changelog/NEXT.md b/.changelog/NEXT.md
index d5f29c894e..8b3f61642b 100644
--- a/.changelog/NEXT.md
+++ b/.changelog/NEXT.md
@@ -99,7 +99,7 @@
- **[issue-1594] The cast representation check now catches per-character dialogue imbalance, not just one dominant voice.** `cast.representation-balance` already flagged the *top* speaker hogging the page, but a lopsided cast can fail two other ways it never saw: a **major character who appears in the prose yet barely speaks** (a lead reduced to a passenger in their own story) and a **minor character who dominates the conversation** (a walk-on whose page time doesn't match the bible). The check now adds a per-character distribution signal that compares each character's attributed dialogue share against their **stated canon role** — classifying the free-text `role` field into a coarse *major* (protagonist, lead, antagonist, …) / *minor* (background, cameo, walk-on, …) / *unknown* tier, and flagging the silent-major and dominant-minor outliers. It reuses the same dialogue attribution the share signal already runs (no extra pass), gates the silent-major case on the character actually appearing in the prose (a major who never appears is *absent*, a different signal — not "oddly silent"), and stays silent on any character whose role is blank, ambiguous, or contradictory ("minor antagonist") rather than guessing — the same absent-vs-empty discipline the gender inference uses. Two new per-series thresholds tune it: a max dialogue share for a minor character (default 35%) and a min share for a major (default 5%), each independently disable-able. It stays a default-on, deterministic, advisory (low-severity) series signal. (`server/lib/editorial/checkRegistry.js`)
-- **[issue-1603] The editorial comment card is now keyboard-drivable, so a triage pass is one keystroke per note instead of a mouse round-trip.** Reviewing findings forced you to reach for the mouse for every Accept / Dismiss / Generate, and stepping between open notes meant detouring back through the sidebar. The open note's card now responds to keyboard shortcuts — **← / →** (or **k / j**, vim-style) to step prev/next through the triage order, **a** to accept the suggested fix, **d** to dismiss, and **g** to generate or regenerate the fix — with an on-screen hint row in the card showing the keys available for that note. The shortcuts never fire while you're typing in the replacement textarea or the manuscript editor (and ⌘/Ctrl chords still reach the browser), so letters never misfire. (`client/src/hooks/useKeyboardShortcuts.js`, `client/src/components/pipeline/manuscript/ManuscriptCommentCard.jsx`)
+- **[issue-1603] The editorial comment card is now keyboard-drivable, so a triage pass is one keystroke per note instead of a mouse round-trip.** Reviewing findings forced you to reach for the mouse for every Accept / Dismiss / Generate, and stepping between open notes meant detouring back through the sidebar. The open note's card now responds to keyboard shortcuts — **← / →** (or **k / j**, vim-style) to step prev/next through the triage order, **a** to accept the suggested fix, **d** to dismiss, and **g** to generate or regenerate the fix — with an on-screen hint row in the card showing the keys available for that note. The shortcuts never fire while you're typing in the replacement textarea or the manuscript editor (and ⌘/Ctrl chords still reach the browser), so letters never misfire. (`client/src/hooks/useKeyboardShortcuts.js`, `client/src/components/pipeline/manuscript/ManuscriptCommentCard.jsx`, `client/src/components/ui/Kbd.jsx`)
## Series Autopilot
diff --git a/client/src/components/KeyboardHelp.jsx b/client/src/components/KeyboardHelp.jsx
index 9368422236..a1d81dc66c 100644
--- a/client/src/components/KeyboardHelp.jsx
+++ b/client/src/components/KeyboardHelp.jsx
@@ -4,6 +4,7 @@ import { useKeyboardHelp } from '../hooks/useKeyboardHelp';
import { useScrollLock } from '../hooks/useScrollLock';
import { modKey } from '../utils/platform';
import Modal from './ui/Modal';
+import Kbd from './ui/Kbd';
const SHORTCUT_SECTIONS = [
{
@@ -32,13 +33,6 @@ const SHORTCUT_SECTIONS = [
},
];
-function Kbd({ children }) {
- return (
- <kbd className="inline-flex items-center justify-center min-w-[24px] h-6 px-1.5 text-xs font-mono font-medium text-gray-300 bg-port-bg border border-port-border rounded shadow-sm">
- {children}
- </kbd>
- );
-}
export default function KeyboardHelp() {
const { open, setOpen } = useKeyboardHelp();
diff --git a/client/src/components/media/MediaLightbox.jsx b/client/src/components/media/MediaLightbox.jsx
index 0c7e64b4a0..f7bcbef259 100644
--- a/client/src/components/media/MediaLightbox.jsx
+++ b/client/src/components/media/MediaLightbox.jsx
@@ -9,6 +9,7 @@ import PinToMoodBoardMenu from './PinToMoodBoardMenu';
import MediaImage from '../MediaImage';
import { useScrollLock } from '../../hooks/useScrollLock';
import { useSwipeNav } from '../../hooks/useSwipeNav';
+import { isEditableTarget } from '../../hooks/useKeyboardShortcuts';
import { copyToClipboard } from '../../lib/clipboard';
import { IMAGE_GEN_MODE } from '../../lib/imageGenBackends';
@@ -36,11 +37,8 @@ const SAVED_INDICATOR_MS = 1500;
// Window-level shortcuts (f, s, arrows) must skip editable targets — otherwise
// typing in the note textarea triggers fullscreen / favorite / nav instead of
// inserting text or moving the caret. Window listeners fire after the target,
-// so preventDefault here still cancels the browser's default text behavior.
-const isEditableTarget = (e) => {
- const t = e.target;
- return !!(t && (t.tagName === 'TEXTAREA' || t.tagName === 'INPUT' || t.isContentEditable));
-};
+// so preventDefault here still cancels the browser's default text behavior. The
+// editable-target check is shared with useKeyboardShortcuts (imported above).
const CLEAN_TOOLTIP = 'Re-encode and denoise: removes the C2PA metadata chunk (when present) and reduces visible AI-generation artifacts. Does NOT defeat SynthID — gpt-image / Imagen / Gemini renders remain detectable by their vendor watermark checkers. Saves a new image alongside the original.';
@@ -143,7 +141,7 @@ export default function MediaLightbox({
cb.onClose();
return;
}
- const inEditable = isEditableTarget(e);
+ const inEditable = isEditableTarget(e.target);
if (e.key === 'f' || e.key === 'F') {
if (inEditable) return;
setFullScreen((v) => !v);
diff --git a/client/src/components/pipeline/manuscript/ManuscriptCommentCard.jsx b/client/src/components/pipeline/manuscript/ManuscriptCommentCard.jsx
index 55876496cc..b9861d8249 100644
--- a/client/src/components/pipeline/manuscript/ManuscriptCommentCard.jsx
+++ b/client/src/components/pipeline/manuscript/ManuscriptCommentCard.jsx
@@ -18,6 +18,7 @@ import toast from '../../ui/Toast';
import { copyToClipboard } from '../../../lib/clipboard';
import { useAsyncAction } from '../../../hooks/useAsyncAction';
import useKeyboardShortcuts from '../../../hooks/useKeyboardShortcuts';
+import Kbd from '../../ui/Kbd';
import {
patchPipelineManuscriptComment, generatePipelineManuscriptFix, acceptPipelineManuscriptFix,
} from '../../../services/api';
@@ -39,15 +40,6 @@ export function CopyId({ id }) {
);
}
-// A single keycap for the on-screen shortcut hints.
-function Kbd({ children }) {
- return (
- <kbd className="rounded border border-port-border bg-port-bg px-1 font-mono text-[9px] leading-tight text-gray-400">
- {children}
- </kbd>
- );
-}
-
// On-screen cheatsheet for the card's keyboard shortcuts (#1603) — only the
// actions actually available for this note are shown (prev/next when the card is
// part of a triage order, Accept/regenerate when a fix exists, Generate when not).
@@ -55,17 +47,17 @@ function ShortcutHints({ hasNav, hasFix }) {
return (
<div className="flex flex-wrap items-center gap-x-2.5 gap-y-1 pt-1.5 text-[10px] text-gray-600">
{hasNav ? (
- <span className="inline-flex items-center gap-1"><Kbd>←</Kbd><Kbd>→</Kbd> step</span>
+ <span className="inline-flex items-center gap-1"><Kbd size="sm">←</Kbd><Kbd size="sm">→</Kbd> step</span>
) : null}
{hasFix ? (
<>
- <span className="inline-flex items-center gap-1"><Kbd>a</Kbd> accept</span>
- <span className="inline-flex items-center gap-1"><Kbd>g</Kbd> regenerate</span>
+ <span className="inline-flex items-center gap-1"><Kbd size="sm">a</Kbd> accept</span>
+ <span className="inline-flex items-center gap-1"><Kbd size="sm">g</Kbd> regenerate</span>
</>
) : (
- <span className="inline-flex items-center gap-1"><Kbd>g</Kbd> generate</span>
+ <span className="inline-flex items-center gap-1"><Kbd size="sm">g</Kbd> generate</span>
)}
- <span className="inline-flex items-center gap-1"><Kbd>d</Kbd> dismiss</span>
+ <span className="inline-flex items-center gap-1"><Kbd size="sm">d</Kbd> dismiss</span>
</div>
);
}
@@ -223,7 +215,7 @@ export default function ManuscriptCommentCard({
ArrowRight: nav?.onNext,
k: nav?.onPrev,
j: nav?.onNext,
- a: hasFix && canAccept && !accepting ? accept : undefined,
+ a: canAccept && !accepting ? accept : undefined,
d: !accepting ? dismiss : undefined,
g: !generating && !accepting ? generate : undefined,
});
diff --git a/client/src/components/ui/Kbd.jsx b/client/src/components/ui/Kbd.jsx
new file mode 100644
index 0000000000..349c7cbc49
--- /dev/null
+++ b/client/src/components/ui/Kbd.jsx
@@ -0,0 +1,15 @@
+// A keycap for rendering a keyboard key in help/cheatsheet UI. Two sizes: `md`
+// (the default — the modal shortcut cheatsheet's roomy cap) and `sm` (a compact
+// inline hint, e.g. the editorial comment card's shortcut row, #1603).
+const SIZE = {
+ md: 'inline-flex items-center justify-center min-w-[24px] h-6 px-1.5 text-xs font-medium text-gray-300 shadow-sm',
+ sm: 'px-1 text-[9px] leading-tight text-gray-400',
+};
+
+export default function Kbd({ children, size = 'md' }) {
+ return (
+ <kbd className={`font-mono bg-port-bg border border-port-border rounded ${SIZE[size] || SIZE.md}`}>
+ {children}
+ </kbd>
+ );
+}