From 85f31a782714516da3850288ae1f854567934092 Mon Sep 17 00:00:00 2001 From: PR Batch Tester Date: Fri, 23 Oct 2026 08:43:17 +0000 Subject: [PATCH 1/2] fix(desktop): annotate PDFs in the preview Chromium draws a PDF in its own viewer frame, so the annotation picker in the tab's page never got pointer input over it. Select, Region and Draw did nothing on a PDF. While annotating a PDF, a transparent layer above the viewer now catches the input, and annotation starts on Region since a PDF has no elements to select. Co-Authored-By: Claude Opus 5.5 --- apps/desktop/src/preview/PickPreload.ts | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/apps/desktop/src/preview/PickPreload.ts b/apps/desktop/src/preview/PickPreload.ts index e49d27d40ba9..72216ab841d0 100644 --- a/apps/desktop/src/preview/PickPreload.ts +++ b/apps/desktop/src/preview/PickPreload.ts @@ -35,6 +35,7 @@ import { START_PICK_CHANNEL, } from "./GuestProtocol.ts"; const OVERLAY_ATTRIBUTE = "data-t3code-annotation-ui"; +const INPUT_LAYER_ATTRIBUTE = "data-t3code-annotation-input"; const Z_INDEX_OVERLAY = 2147483646; const PRIMARY = "var(--t3-primary)"; const PRIMARY_FILL = "color-mix(in srgb, var(--t3-primary) 10%, transparent)"; @@ -268,7 +269,7 @@ function isAnnotationNode(element: Element): boolean { function pickFromPoint(clientX: number, clientY: number): Element | null { for (const candidate of document.elementsFromPoint(clientX, clientY)) { if (!(candidate instanceof Element)) continue; - if (isAnnotationNode(candidate)) continue; + if (isAnnotationNode(candidate) || candidate.hasAttribute(INPUT_LAYER_ATTRIBUTE)) continue; if (candidate === document.documentElement || candidate === document.body) continue; return candidate; } @@ -636,7 +637,16 @@ function startAnnotation(sendEnabled: boolean): void { const strokes: PreviewAnnotationStrokeTarget[] = []; const styleChanges = new Map(); const toolButtons = new Map(); - let tool: AnnotationTool = "select"; + // Chromium draws a PDF in its own viewer frame, so pointer input over it never + // reaches this document. A transparent layer above the viewer catches it instead. + // A PDF has no elements to select, so it starts on Region. + const isPdf = document.contentType === "application/pdf"; + const inputLayer = isPdf ? document.createElement("div") : null; + if (inputLayer) { + inputLayer.setAttribute(INPUT_LAYER_ATTRIBUTE, ""); + inputLayer.style.cssText = `position:fixed;inset:0;z-index:${Z_INDEX_OVERLAY - 1};cursor:crosshair`; + } + let tool: AnnotationTool = isPdf ? "marquee" : "select"; let dragStart: PreviewAnnotationPoint | null = null; let activeStroke: { target: PreviewAnnotationStrokeTarget; path: SVGPathElement } | null = null; let pendingCapture = false; @@ -1356,6 +1366,7 @@ function startAnnotation(sendEnabled: boolean): void { ipcRenderer.off(ANNOTATION_CAPTURED_CHANNEL, onCaptured); document.documentElement.removeAttribute("data-t3code-annotation-tool"); cursorStyle.remove(); + inputLayer?.remove(); host.remove(); activeSession = null; if (notifyMain) ipcRenderer.send(ELEMENT_PICKED_CHANNEL, null); @@ -1467,6 +1478,7 @@ function startAnnotation(sendEnabled: boolean): void { window.addEventListener("resize", repaint, { passive: true }); ipcRenderer.on(CANCEL_PICK_CHANNEL, onCancel); ipcRenderer.on(ANNOTATION_CAPTURED_CHANNEL, onCaptured); + if (inputLayer) document.documentElement.appendChild(inputLayer); document.documentElement.appendChild(host); rootResizeObserver.observe(document.documentElement); refreshToolButtons(); From a63f9a93779bea3b25e1d41249a21c2164135e94 Mon Sep 17 00:00:00 2001 From: PR Batch Tester Date: Fri, 23 Oct 2026 08:55:58 +0000 Subject: [PATCH 2/2] fix(desktop): Escape and tool keys work while annotating a PDF Chrome's PDF viewer keeps keyboard focus, so Escape and the R/D/E keys went to the viewer instead of the annotator. The PDF input layer now takes focus when annotation starts. Co-Authored-By: Claude Opus 5.5 --- apps/desktop/src/preview/PickPreload.ts | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/apps/desktop/src/preview/PickPreload.ts b/apps/desktop/src/preview/PickPreload.ts index 72216ab841d0..4059468da22e 100644 --- a/apps/desktop/src/preview/PickPreload.ts +++ b/apps/desktop/src/preview/PickPreload.ts @@ -637,14 +637,16 @@ function startAnnotation(sendEnabled: boolean): void { const strokes: PreviewAnnotationStrokeTarget[] = []; const styleChanges = new Map(); const toolButtons = new Map(); - // Chromium draws a PDF in its own viewer frame, so pointer input over it never - // reaches this document. A transparent layer above the viewer catches it instead. - // A PDF has no elements to select, so it starts on Region. + // Chromium draws a PDF in its own viewer frame, so pointer and key input over it + // never reaches this document. A transparent layer above the viewer catches the + // pointer and takes focus for Escape and the tool keys. A PDF has no elements to + // select, so it starts on Region. const isPdf = document.contentType === "application/pdf"; const inputLayer = isPdf ? document.createElement("div") : null; if (inputLayer) { inputLayer.setAttribute(INPUT_LAYER_ATTRIBUTE, ""); - inputLayer.style.cssText = `position:fixed;inset:0;z-index:${Z_INDEX_OVERLAY - 1};cursor:crosshair`; + inputLayer.tabIndex = -1; + inputLayer.style.cssText = `position:fixed;inset:0;z-index:${Z_INDEX_OVERLAY - 1};cursor:crosshair;outline:none`; } let tool: AnnotationTool = isPdf ? "marquee" : "select"; let dragStart: PreviewAnnotationPoint | null = null; @@ -1478,7 +1480,10 @@ function startAnnotation(sendEnabled: boolean): void { window.addEventListener("resize", repaint, { passive: true }); ipcRenderer.on(CANCEL_PICK_CHANNEL, onCancel); ipcRenderer.on(ANNOTATION_CAPTURED_CHANNEL, onCaptured); - if (inputLayer) document.documentElement.appendChild(inputLayer); + if (inputLayer) { + document.documentElement.appendChild(inputLayer); + inputLayer.focus({ preventScroll: true }); + } document.documentElement.appendChild(host); rootResizeObserver.observe(document.documentElement); refreshToolButtons();