GeezerVison is showing github.com — fix(desktop): annotation tool keys work after clicking a toolbar butt… · pingdotgg/t3code@4bf4ae7
File treeExpand file treeCollapse file tree Open diff view settings Expand file treeCollapse file tree Open diff view settings Collapse file Copy file name to clipboardExpand all lines: apps/desktop/package.json +1Lines changed: 1 addition & 0 deletions | Original file line number | Diff line number | Diff line change |
|---|
| 37 | 37 | "acorn": "8.16.0", | 38 | 38 | "cross-env": "^10.1.0", | 39 | 39 | "electron-builder": "26.16.1", | | 40 | + "jsdom": "^30.0.1", | 40 | 41 | "tailwindcss": "^4.0.0", | 41 | 42 | "vite-plus": "catalog:" | 42 | 43 | }, | |
Collapse file Copy file name to clipboard +64Lines changed: 64 additions & 0 deletions | Original file line number | Diff line number | Diff line change |
|---|
| | 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 | +}); |
Collapse file Copy file name to clipboardExpand all lines: apps/desktop/src/preview/PickPreload.ts +1-1Lines changed: 1 addition & 1 deletion | Original file line number | Diff line number | Diff line change |
|---|
@@ -1673,13 +1673,13 @@ function startAnnotation( | 1673 | 1673 | return; | 1674 | 1674 | } | 1675 | 1675 | } | 1676 | | - if (isAnnotationNode(event.target as Element) && event.key !== "Escape") return; | 1677 | 1676 | if (event.key === "Escape") { | 1678 | 1677 | event.preventDefault(); | 1679 | 1678 | event.stopPropagation(); | 1680 | 1679 | teardown(true); | 1681 | 1680 | return; | 1682 | 1681 | } | | 1682 | + if (shadowRoot.activeElement?.matches("input, textarea, select")) return; | 1683 | 1683 | if (event.key === "v") tool = "select"; | 1684 | 1684 | else if (event.key === "r") tool = "marquee"; | 1685 | 1685 | else if (event.key === "d") tool = "draw"; | |
Collapse file Copy file name to clipboardExpand all lines: apps/desktop/vite.config.ts +24-4Lines changed: 24 additions & 4 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -5,6 +5,7 @@ import { isDesktopRuntimeExternalDependency } from "../../scripts/lib/desktop-ex | 5 | 5 | import { loadRepoEnv } from "../../scripts/lib/public-config.ts"; | 6 | 6 |
| 7 | 7 | const repoEnv = loadRepoEnv(); | | 8 | +const domTests = ["src/preview/PickPreload.test.ts"]; | 8 | 9 |
| 9 | 10 | // Install only bundle externals; the server bundle already carries its dependency tree. | 10 | 11 | const isMainProcessExternal = (id: string) => | @@ -151,13 +152,32 @@ export default defineConfig({ | 151 | 152 | }, | 152 | 153 | ], | 153 | 154 | test: { | 154 | | - include: [...defaultInclude, "../../native/kde-snap-shot/src/*.test.ts"], | 155 | 155 | // The Windows lane runs workspace suites concurrently; filesystem-heavy | 156 | 156 | // desktop integration tests can exceed Vitest's 5 second default there. | 157 | 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 | + }, | 161 | 181 | ], | 162 | 182 | }, | 163 | 183 | }); |
Collapse file Copy file name to clipboardExpand all lines: pnpm-lock.yaml +3Lines changed: 3 additions & 0 deletions
|