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; }