Skip to content

Commit 17817b6

Browse files
fix(web): let the shortcut recorder capture the reopen chord
The reopen shortcut listens in the capture phase, so while closed-view history existed it swallowed mod+shift+t before the Settings recorder saw it, and focusing the recorder to rebind the chord reopened a view instead. Skip keybinding-capture targets, as the sidebar toggle does. Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
1 parent 7b5340c commit 17817b6

2 files changed

Lines changed: 28 additions & 1 deletion

File tree

‎apps/web/src/components/ReopenClosedViewShortcut.test.tsx‎

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,11 @@ import { useTerminalUiStateStore } from "../terminalUiStateStore";
8383
import { ReopenClosedViewShortcut } from "./ReopenClosedViewShortcut";
8484

8585
const ref = { environmentId: "remote", threadId: "thread-1" } as ScopedThreadRef;
86+
class TestElement extends EventTarget {
87+
closest(selector: string) {
88+
return selector === "[data-keybinding-capture]" ? this : null;
89+
}
90+
}
8691
let renderer: ReactTestRenderer | undefined;
8792
let menuAction: ((action: string) => void) | undefined;
8893

@@ -128,6 +133,7 @@ beforeEach(() => {
128133
suppressedTerminalIdsByThreadKey: {},
129134
});
130135
vi.stubGlobal("IS_REACT_ACT_ENVIRONMENT", true);
136+
vi.stubGlobal("HTMLElement", TestElement);
131137
vi.stubGlobal("navigator", { platform: "Linux" });
132138
vi.stubGlobal(
133139
"window",
@@ -179,6 +185,26 @@ describe("root reopen shortcut", () => {
179185
expect(useClosedViewStore.getState().entries).toHaveLength(1);
180186
});
181187

188+
it("lets the keybinding recorder capture the chord", async () => {
189+
useClosedViewStore
190+
.getState()
191+
.remember({ kind: "panel-tab", threadRef: ref, surface: { kind: "diff", id: "diff" } });
192+
await render();
193+
const recorder = new TestElement();
194+
const event = Object.assign(new Event("keydown", { bubbles: true, cancelable: true }), {
195+
key: "T",
196+
ctrlKey: true,
197+
metaKey: false,
198+
shiftKey: true,
199+
altKey: false,
200+
repeat: false,
201+
});
202+
Object.defineProperty(event, "target", { value: recorder });
203+
window.dispatchEvent(event);
204+
expect(event.defaultPrevented).toBe(false);
205+
expect(useClosedViewStore.getState().entries).toHaveLength(1);
206+
});
207+
182208
it("honors custom chords and when conditions, and consumes repeats without restoring", async () => {
183209
state.keybindings = [
184210
{

‎apps/web/src/components/ReopenClosedViewShortcut.tsx‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -188,7 +188,8 @@ export function ReopenClosedViewShortcut() {
188188
if (
189189
event.defaultPrevented ||
190190
isCommandPaletteOpen() ||
191-
useClosedViewStore.getState().entries.length === 0
191+
useClosedViewStore.getState().entries.length === 0 ||
192+
(event.target instanceof HTMLElement && event.target.closest("[data-keybinding-capture]"))
192193
)
193194
return;
194195
const command = resolveShortcutCommand(event, keybindings, {

0 commit comments

Comments
 (0)