Fix issue detail inbox archive shortcut

This commit is contained in:
dotta 2026-04-08 08:56:07 -05:00
parent 296033620f
commit e21e442033
3 changed files with 11 additions and 50 deletions

View file

@ -55,7 +55,7 @@ describe("keyboardShortcuts helpers", () => {
})).toBe("archive");
});
it("disarms on the first non-y keypress", () => {
it("ignores non-y keypresses", () => {
const button = document.createElement("button");
expect(resolveInboxQuickArchiveKeyAction({
@ -67,7 +67,7 @@ describe("keyboardShortcuts helpers", () => {
altKey: false,
target: button,
hasOpenDialog: false,
})).toBe("disarm");
})).toBe("ignore");
});
it("stays inert for modifier combos before a real keypress", () => {
@ -96,7 +96,7 @@ describe("keyboardShortcuts helpers", () => {
})).toBe("ignore");
});
it("disarms instead of archiving when typing into an editor", () => {
it("ignores input typing instead of archiving", () => {
const input = document.createElement("input");
expect(resolveInboxQuickArchiveKeyAction({
@ -108,7 +108,7 @@ describe("keyboardShortcuts helpers", () => {
altKey: false,
target: input,
hasOpenDialog: false,
})).toBe("disarm");
})).toBe("ignore");
});
it("arms go-to-inbox on a clean g press", () => {

View file

@ -47,11 +47,11 @@ export function resolveInboxQuickArchiveKeyAction({
hasOpenDialog: boolean;
}): InboxQuickArchiveKeyAction {
if (!armed) return "ignore";
if (defaultPrevented) return "disarm";
if (defaultPrevented) return "ignore";
if (metaKey || ctrlKey || altKey || isModifierOnlyKey(key)) return "ignore";
if (hasOpenDialog || isKeyboardShortcutTextInputTarget(target)) return "disarm";
if (key === "y") return "archive";
return "disarm";
if (hasOpenDialog || isKeyboardShortcutTextInputTarget(target)) return "ignore";
if (key.toLowerCase() === "y") return "archive";
return "ignore";
}
export function resolveGoToInboxKeyAction({

View file

@ -24,7 +24,6 @@ import {
readIssueDetailLocationState,
readIssueDetailBreadcrumb,
rememberIssueDetailLocationState,
shouldArmIssueDetailInboxQuickArchive,
} from "../lib/issueDetailBreadcrumb";
import {
hasBlockingShortcutDialog,
@ -1235,46 +1234,17 @@ export function IssueDetail() {
return () => closePanel();
}, [closePanel, handleIssuePropertiesUpdate, issuePanelKey, openNewSubIssue, openPanel]);
const inboxQuickArchiveArmedRef = useRef(false);
const goToInboxShortcutArmedRef = useRef(false);
const goToInboxShortcutTimeoutRef = useRef<number | null>(null);
const canQuickArchiveFromInbox =
keyboardShortcutsEnabled &&
!issue?.hiddenAt &&
sourceBreadcrumb.href.startsWith("/inbox") &&
shouldArmIssueDetailInboxQuickArchive(location.state);
!issue?.hiddenAt;
useEffect(() => {
if (!issue?.id || !canQuickArchiveFromInbox) {
inboxQuickArchiveArmedRef.current = false;
return;
}
inboxQuickArchiveArmedRef.current = true;
const disarm = () => {
inboxQuickArchiveArmedRef.current = false;
};
const handlePointerDown = () => {
disarm();
};
const handleFocusIn = (event: FocusEvent) => {
if (event.target instanceof HTMLElement && event.target !== document.body) {
disarm();
}
};
const handleSelectionChange = () => {
const selection = window.getSelection();
if (!selection || selection.isCollapsed || selection.toString().trim().length === 0) return;
disarm();
};
if (!issue?.id || !canQuickArchiveFromInbox) return;
const handleKeyDown = (event: KeyboardEvent) => {
const action = resolveInboxQuickArchiveKeyAction({
armed: inboxQuickArchiveArmedRef.current,
armed: canQuickArchiveFromInbox,
defaultPrevented: event.defaultPrevented,
key: event.key,
metaKey: event.metaKey,
@ -1284,9 +1254,6 @@ export function IssueDetail() {
hasOpenDialog: hasBlockingShortcutDialog(document),
});
if (action === "ignore") return;
disarm();
if (action !== "archive") return;
event.preventDefault();
@ -1295,14 +1262,8 @@ export function IssueDetail() {
}
};
document.addEventListener("pointerdown", handlePointerDown, true);
document.addEventListener("focusin", handleFocusIn, true);
document.addEventListener("selectionchange", handleSelectionChange);
document.addEventListener("keydown", handleKeyDown, true);
return () => {
document.removeEventListener("pointerdown", handlePointerDown, true);
document.removeEventListener("focusin", handleFocusIn, true);
document.removeEventListener("selectionchange", handleSelectionChange);
document.removeEventListener("keydown", handleKeyDown, true);
};
}, [archiveFromInbox, canQuickArchiveFromInbox, issue?.id]);