From 7d7b3e078950f4ba2c303c3b5309928578b708f7 Mon Sep 17 00:00:00 2001 From: devzain15 <195662226+devzain15@users.noreply.github.com> Date: Fri, 23 Oct 2026 22:40:50 +0500 Subject: [PATCH] fix: let r reply to the commit a page shows On a commit page, r, q, o and y did nothing until a commit had keyboard focus, which is not obvious on a page about one commit. Without a focused commit, the shortcuts now act on the commit the page shows. Closes #984 --- resources/js/components/commit-card.tsx | 1 + resources/js/hooks/use-keyboard-shortcuts.ts | 12 +++++++----- 2 files changed, 8 insertions(+), 5 deletions(-) diff --git a/resources/js/components/commit-card.tsx b/resources/js/components/commit-card.tsx index c507e6155..a7083ae8a 100644 --- a/resources/js/components/commit-card.tsx +++ b/resources/js/components/commit-card.tsx @@ -249,6 +249,7 @@ export function CommitCard({ )} tabIndex={-1} data-commit={commit.id} + data-focused={isFocused || undefined} data-permalink={wasDeleted ? undefined : permalink.url} data-test="commit" onClick={openClickedCommit} diff --git a/resources/js/hooks/use-keyboard-shortcuts.ts b/resources/js/hooks/use-keyboard-shortcuts.ts index 0c5bb1c53..7dfb475e2 100644 --- a/resources/js/hooks/use-keyboard-shortcuts.ts +++ b/resources/js/hooks/use-keyboard-shortcuts.ts @@ -43,14 +43,16 @@ export function focusCommit(commit: HTMLElement): void { } /** + * Without a focused commit, the shortcuts act on the commit a page is about, so r replies to it straight away. * A deleted commit's actions are inert, which stops pointers and focus but not a scripted click. */ function focusedCommitAction(key: string): HTMLButtonElement | null { - const action = document.activeElement - ?.closest('[data-commit]') - ?.querySelector( - `button[aria-keyshortcuts="${CSS.escape(key)}"]`, - ); + const commit = + document.activeElement?.closest('[data-commit]') ?? + document.querySelector('[data-commit][data-focused]'); + const action = commit?.querySelector( + `button[aria-keyshortcuts="${CSS.escape(key)}"]`, + ); return action && !action.closest('[inert]') ? action : null; }