@devries-cameron20 / t3code-1 / commits / 6ba807810b
Fork 0

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

fix(desktop): PDFs in the preview can be annotated (#24022)

Co-authored-by: PR Batch Tester <agent@local.test> Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>

shivam committed Oct 23, 2026 at 17:09 UTC 6ba807810b2fa93ed5ef75fde82639f7007868e4
1 file changed +19 -2
apps/desktop/src/preview/PickPreload.ts
+19 -2
@@ -35,6 +35,7 @@ import {
35 START_PICK_CHANNEL,
36 } from "./GuestProtocol.ts";
37 const OVERLAY_ATTRIBUTE = "data-t3code-annotation-ui";
38 +const INPUT_LAYER_ATTRIBUTE = "data-t3code-annotation-input";
39 const Z_INDEX_OVERLAY = 2147483646;
40 const PRIMARY = "var(--t3-primary)";
41 const PRIMARY_FILL = "color-mix(in srgb, var(--t3-primary) 10%, transparent)";
@@ -268,7 +269,7 @@ function isAnnotationNode(element: Element): boolean {
269 function pickFromPoint(clientX: number, clientY: number): Element | null {
270 for (const candidate of document.elementsFromPoint(clientX, clientY)) {
271 if (!(candidate instanceof Element)) continue;
271 - if (isAnnotationNode(candidate)) continue;
272 + if (isAnnotationNode(candidate) || candidate.hasAttribute(INPUT_LAYER_ATTRIBUTE)) continue;
273 if (candidate === document.documentElement || candidate === document.body) continue;
274 return candidate;
275 }
@@ -636,7 +637,18 @@ function startAnnotation(sendEnabled: boolean): void {
637 const strokes: PreviewAnnotationStrokeTarget[] = [];
638 const styleChanges = new Map<string, PreviewAnnotationStyleChange>();
639 const toolButtons = new Map<AnnotationTool, HTMLButtonElement>();
639 - let tool: AnnotationTool = "select";
640 + // Chromium draws a PDF in its own viewer frame, so pointer and key input over it
641 + // never reaches this document. A transparent layer above the viewer catches the
642 + // pointer and takes focus for Escape and the tool keys. A PDF has no elements to
643 + // select, so it starts on Region.
644 + const isPdf = document.contentType === "application/pdf";
645 + const inputLayer = isPdf ? document.createElement("div") : null;
646 + if (inputLayer) {
647 + inputLayer.setAttribute(INPUT_LAYER_ATTRIBUTE, "");
648 + inputLayer.tabIndex = -1;
649 + inputLayer.style.cssText = `position:fixed;inset:0;z-index:${Z_INDEX_OVERLAY - 1};cursor:crosshair;outline:none`;
650 + }
651 + let tool: AnnotationTool = isPdf ? "marquee" : "select";
652 let dragStart: PreviewAnnotationPoint | null = null;
653 let activeStroke: { target: PreviewAnnotationStrokeTarget; path: SVGPathElement } | null = null;
654 let pendingCapture = false;
@@ -1356,6 +1368,7 @@ function startAnnotation(sendEnabled: boolean): void {
1368 ipcRenderer.off(ANNOTATION_CAPTURED_CHANNEL, onCaptured);
1369 document.documentElement.removeAttribute("data-t3code-annotation-tool");
1370 cursorStyle.remove();
1371 + inputLayer?.remove();
1372 host.remove();
1373 activeSession = null;
1374 if (notifyMain) ipcRenderer.send(ELEMENT_PICKED_CHANNEL, null);
@@ -1467,6 +1480,10 @@ function startAnnotation(sendEnabled: boolean): void {
1480 window.addEventListener("resize", repaint, { passive: true });
1481 ipcRenderer.on(CANCEL_PICK_CHANNEL, onCancel);
1482 ipcRenderer.on(ANNOTATION_CAPTURED_CHANNEL, onCaptured);
1483 + if (inputLayer) {
1484 + document.documentElement.appendChild(inputLayer);
1485 + inputLayer.focus({ preventScroll: true });
1486 + }
1487 document.documentElement.appendChild(host);
1488 rootResizeObserver.observe(document.documentElement);
1489 refreshToolButtons();