Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions resources/js/components/commit-card.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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}
Expand Down
12 changes: 7 additions & 5 deletions resources/js/hooks/use-keyboard-shortcuts.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<HTMLButtonElement>(
`button[aria-keyshortcuts="${CSS.escape(key)}"]`,
);
const commit =
document.activeElement?.closest('[data-commit]') ??
document.querySelector('[data-commit][data-focused]');
const action = commit?.querySelector<HTMLButtonElement>(
`button[aria-keyshortcuts="${CSS.escape(key)}"]`,
);

return action && !action.closest('[inert]') ? action : null;
}
Expand Down