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, 23:30 UTC
fix(desktop): annotation tool keys work after clicking a toolbar button (#26211)
Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
Julius Marminge committed
Nov 11, 2026 at 11:51 UTC
4bf4ae74ac7288947261b1cd5ead2f427c3eee1c
5 files changed
+93
-5
apps/desktop/package.json
+1
@@ -37,6 +37,7 @@
37
"acorn": "8.16.0",
38
"cross-env": "^10.1.0",
39
"electron-builder": "26.16.1",
40
+ "jsdom": "^30.0.1",
41
"tailwindcss": "^4.0.0",
42
"vite-plus": "catalog:"
43
},
apps/desktop/src/preview/PickPreload.test.ts
new
+64
@@ -0,0 +1,64 @@
1
+import { expect, it, vi } from "vite-plus/test";
2
+
3
+import { START_PICK_CHANNEL } from "./GuestProtocol.ts";
4
+import "./PickPreload.ts";
5
+
6
+const ipcListeners = vi.hoisted(() => new Map<string, Array<(...args: unknown[]) => void>>());
7
+
8
+vi.mock("electron", () => ({
9
+ ipcRenderer: {
10
+ on: (channel: string, listener: (...args: unknown[]) => void) => {
11
+ ipcListeners.set(channel, [...(ipcListeners.get(channel) ?? []), listener]);
12
+ },
13
+ off: () => {},
14
+ send: () => {},
15
+ invoke: async () => undefined,
16
+ },
17
+}));
18
+
19
+vi.mock("react-grab/primitives", () => ({ getElementContext: async () => null }));
20
+
21
+const startAnnotation = (): ShadowRoot => {
22
+ vi.stubGlobal(
23
+ "ResizeObserver",
24
+ class {
25
+ observe() {}
26
+ disconnect() {}
27
+ },
28
+ );
29
+ using attachShadow = vi.spyOn(Element.prototype, "attachShadow");
30
+ for (const listener of ipcListeners.get(START_PICK_CHANNEL) ?? []) listener({}, undefined, false);
31
+ const shadowRoot = attachShadow.mock.results[0]?.value;
32
+ if (!(shadowRoot instanceof ShadowRoot)) throw new Error("annotation overlay did not start");
33
+ return shadowRoot;
34
+};
35
+
36
+it("switches tools from the keyboard after a toolbar button is clicked", () => {
37
+ const shadowRoot = startAnnotation();
38
+ const region = Array.from(shadowRoot.querySelectorAll("button")).find(
39
+ (button) => button.textContent === "Region",
40
+ );
41
+ if (!region) throw new Error("Region toolbar button not found");
42
+
43
+ region.focus();
44
+ region.click();
45
+ expect(document.documentElement.getAttribute("data-t3code-annotation-tool")).toBe("marquee");
46
+
47
+ region.dispatchEvent(new KeyboardEvent("keydown", { key: "v", bubbles: true, composed: true }));
48
+
49
+ expect(
50
+ document.documentElement.getAttribute("data-t3code-annotation-tool"),
51
+ "V should switch to Select while focus is on a toolbar button",
52
+ ).toBe("select");
53
+});
54
+
55
+it("keeps the tool while typing a tool key in the comment", () => {
56
+ const shadowRoot = startAnnotation();
57
+ const comment = shadowRoot.querySelector("textarea");
58
+ if (!comment) throw new Error("comment textarea not found");
59
+
60
+ comment.focus();
61
+ comment.dispatchEvent(new KeyboardEvent("keydown", { key: "r", bubbles: true, composed: true }));
62
+
63
+ expect(document.documentElement.getAttribute("data-t3code-annotation-tool")).toBe("select");
64
+});
apps/desktop/src/preview/PickPreload.ts
+1
-1
@@ -1673,13 +1673,13 @@ function startAnnotation(
1673
return;
1674
}
1675
}
1676
- if (isAnnotationNode(event.target as Element) && event.key !== "Escape") return;
1676
if (event.key === "Escape") {
1677
event.preventDefault();
1678
event.stopPropagation();
1679
teardown(true);
1680
return;
1681
}
1682
+ if (shadowRoot.activeElement?.matches("input, textarea, select")) return;
1683
if (event.key === "v") tool = "select";
1684
else if (event.key === "r") tool = "marquee";
1685
else if (event.key === "d") tool = "draw";
apps/desktop/vite.config.ts
+24
-4
@@ -5,6 +5,7 @@ import { isDesktopRuntimeExternalDependency } from "../../scripts/lib/desktop-ex
5
import { loadRepoEnv } from "../../scripts/lib/public-config.ts";
6
7
const repoEnv = loadRepoEnv();
8
+const domTests = ["src/preview/PickPreload.test.ts"];
9
10
// Install only bundle externals; the server bundle already carries its dependency tree.
11
const isMainProcessExternal = (id: string) =>
@@ -151,13 +152,32 @@ export default defineConfig({
152
},
153
],
154
test: {
154
- include: [...defaultInclude, "../../native/kde-snap-shot/src/*.test.ts"],
155
// The Windows lane runs workspace suites concurrently; filesystem-heavy
156
// desktop integration tests can exceed Vitest's 5 second default there.
157
testTimeout: 15_000,
158
- setupFiles: [
159
- "../../packages/shared/src/testing/longTempDir.ts",
160
- "../../packages/shared/src/testing/providerEnv.ts",
158
+ projects: [
159
+ {
160
+ extends: true,
161
+ test: {
162
+ name: "unit",
163
+ include: [...defaultInclude, "../../native/kde-snap-shot/src/*.test.ts"],
164
+ exclude: ["**/node_modules/**", ...domTests],
165
+ setupFiles: [
166
+ "../../packages/shared/src/testing/longTempDir.ts",
167
+ "../../packages/shared/src/testing/providerEnv.ts",
168
+ ],
169
+ },
170
+ },
171
+ {
172
+ extends: true,
173
+ test: {
174
+ name: "dom",
175
+ include: domTests,
176
+ // Guest preloads run in the page; these tests drive them against a DOM.
177
+ environment: "jsdom",
178
+ setupFiles: ["../../packages/shared/src/testing/providerEnv.ts"],
179
+ },
180
+ },
181
],
182
},
183
});
pnpm-lock.yaml
+3
@@ -491,6 +491,9 @@ importers:
491
electron-builder:
492
specifier: 26.16.1
493
version: 26.16.1(electron-builder-squirrel-windows@26.16.1)(supports-color@8.1.1)
494
+ jsdom:
495
+ specifier: ^30.0.1
496
+ version: 30.1.0(@noble/hashes@1.8.0)
497
tailwindcss:
498
specifier: 4.3.3
499
version: 4.3.3