Skip to content

Commit a63f9a9

Browse files
PR Batch Testerclaude
andcommitted
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 <[email protected]>
1 parent 85f31a7 commit a63f9a9

1 file changed

Lines changed: 10 additions & 5 deletions

File tree

‎apps/desktop/src/preview/PickPreload.ts‎

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -637,14 +637,16 @@ function startAnnotation(sendEnabled: boolean): void {
637637
const strokes: PreviewAnnotationStrokeTarget[] = [];
638638
const styleChanges = new Map<string, PreviewAnnotationStyleChange>();
639639
const toolButtons = new Map<AnnotationTool, HTMLButtonElement>();
640-
// Chromium draws a PDF in its own viewer frame, so pointer input over it never
641-
// reaches this document. A transparent layer above the viewer catches it instead.
642-
// A PDF has no elements to select, so it starts on Region.
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.
643644
const isPdf = document.contentType === "application/pdf";
644645
const inputLayer = isPdf ? document.createElement("div") : null;
645646
if (inputLayer) {
646647
inputLayer.setAttribute(INPUT_LAYER_ATTRIBUTE, "");
647-
inputLayer.style.cssText = `position:fixed;inset:0;z-index:${Z_INDEX_OVERLAY - 1};cursor:crosshair`;
648+
inputLayer.tabIndex = -1;
649+
inputLayer.style.cssText = `position:fixed;inset:0;z-index:${Z_INDEX_OVERLAY - 1};cursor:crosshair;outline:none`;
648650
}
649651
let tool: AnnotationTool = isPdf ? "marquee" : "select";
650652
let dragStart: PreviewAnnotationPoint | null = null;
@@ -1478,7 +1480,10 @@ function startAnnotation(sendEnabled: boolean): void {
14781480
window.addEventListener("resize", repaint, { passive: true });
14791481
ipcRenderer.on(CANCEL_PICK_CHANNEL, onCancel);
14801482
ipcRenderer.on(ANNOTATION_CAPTURED_CHANNEL, onCaptured);
1481-
if (inputLayer) document.documentElement.appendChild(inputLayer);
1483+
if (inputLayer) {
1484+
document.documentElement.appendChild(inputLayer);
1485+
inputLayer.focus({ preventScroll: true });
1486+
}
14821487
document.documentElement.appendChild(host);
14831488
rootResizeObserver.observe(document.documentElement);
14841489
refreshToolButtons();

0 commit comments

Comments
 (0)