@devries-cameron20 / t3code Mirror · read-only / commits / 65057562b7
Fork 0

The best way to control Claude Code, Codex and more from any computer or phone

Mirrored from https://github.com/Camo67/t3code.git

Synced Nov 21, 19:45 UTC

fix(desktop): preview comment keystrokes no longer trigger the page's shortcuts (#35431)

Julius Marminge committed Nov 12, 2026 at 10:16 UTC 65057562b79d71be6e5cf0dde33846ecdc10bf98
2 files changed +43 -5
apps/desktop/src/preview/PickPreload.test.ts
+22
@@ -62,3 +62,25 @@ it("keeps the tool while typing a tool key in the comment", () => {
62
63 expect(document.documentElement.getAttribute("data-t3code-annotation-tool")).toBe("select");
64 });
65 +
66 +it("keeps comment keystrokes away from the page's capture-phase shortcuts", () => {
67 + const pageShortcut = vi.fn((event: KeyboardEvent) => event.preventDefault());
68 + window.addEventListener("keydown", pageShortcut, { capture: true });
69 + const shadowRoot = startAnnotation();
70 + const comment = shadowRoot.querySelector("textarea");
71 + if (!comment) throw new Error("comment textarea not found");
72 +
73 + comment.focus();
74 + const space = new KeyboardEvent("keydown", {
75 + key: " ",
76 + code: "Space",
77 + bubbles: true,
78 + cancelable: true,
79 + composed: true,
80 + });
81 + comment.dispatchEvent(space);
82 + window.removeEventListener("keydown", pageShortcut, { capture: true });
83 +
84 + expect(pageShortcut).not.toHaveBeenCalled();
85 + expect(space.defaultPrevented).toBe(false);
86 +});
apps/desktop/src/preview/PickPreload.ts
+21 -5
@@ -149,6 +149,7 @@ interface AnnotationSession {
149 teardown: (notifyMain: boolean) => void;
150 applyTheme: (theme: DesktopPreviewAnnotationTheme) => void;
151 setSendEnabled: (enabled: boolean) => void;
152 + handleOverlayKey: (event: KeyboardEvent) => void;
153 }
154
155 let activeSession: AnnotationSession | null = null;
@@ -225,6 +226,18 @@ const reportUnhandledShortcut = (event: KeyboardEvent): void => {
226
227 window.addEventListener("keydown", reportUnhandledShortcut, true);
228
229 +// Registered before page scripts so their capture listeners never see keys typed into the
230 +// overlay; the closed shadow root retargets those to the host, hiding that they edit text.
231 +const isolateOverlayKey = (event: KeyboardEvent): void => {
232 + if (!activeSession || !(event.target instanceof Element) || !isAnnotationNode(event.target))
233 + return;
234 + activeSession.handleOverlayKey(event);
235 + event.stopImmediatePropagation();
236 +};
237 +
238 +for (const type of ["keydown", "keypress", "keyup"] as const)
239 + window.addEventListener(type, isolateOverlayKey, true);
240 +
241 const MOUSE_BUTTON_BACK = 3;
242 const MOUSE_BUTTON_FORWARD = 4;
243
@@ -1762,15 +1775,17 @@ function startAnnotation(
1775 });
1776 };
1777 submit.addEventListener("click", () => submitAnnotation("attach"));
1765 - root.addEventListener("keydown", (event) => {
1778 + const handleOverlayKey = (event: KeyboardEvent): void => {
1779 + if (event.type === "keyup") onVoiceKeyUp(event);
1780 + if (event.type !== "keydown") return;
1781 + onKeyDown(event);
1782 + if (event.cancelBubble) return;
1783 const submission =
1767 - event.target === comment ? resolveAnnotationSubmission(event, sendEnabled) : null;
1768 - // Bubble phase lets editor inputs handle events before hiding them from the page.
1769 - event.stopImmediatePropagation();
1784 + shadowRoot.activeElement === comment ? resolveAnnotationSubmission(event, sendEnabled) : null;
1785 if (!submission) return;
1786 event.preventDefault();
1787 submitAnnotation(submission);
1773 - });
1788 + };
1789
1790 window.addEventListener("pointermove", onPointerMove, { capture: true, passive: false });
1791 window.addEventListener("pointerdown", onPointerDown, { capture: true, passive: false });
@@ -1806,6 +1821,7 @@ function startAnnotation(
1821 sendEnabled = enabled;
1822 updateSendHint();
1823 },
1824 + handleOverlayKey,
1825 };
1826 }
1827