Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 19 additions & 2 deletions apps/desktop/src/preview/PickPreload.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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)";
Expand Down Expand Up @@ -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;
}
Expand Down Expand Up @@ -636,7 +637,18 @@ function startAnnotation(sendEnabled: boolean): void {
const strokes: PreviewAnnotationStrokeTarget[] = [];
const styleChanges = new Map<string, PreviewAnnotationStyleChange>();
const toolButtons = new Map<AnnotationTool, HTMLButtonElement>();
let tool: AnnotationTool = "select";
// 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.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;
let activeStroke: { target: PreviewAnnotationStrokeTarget; path: SVGPathElement } | null = null;
let pendingCapture = false;
Expand Down Expand Up @@ -1356,6 +1368,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);
Expand Down Expand Up @@ -1467,6 +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);
inputLayer.focus({ preventScroll: true });
}
document.documentElement.appendChild(host);
rootResizeObserver.observe(document.documentElement);
refreshToolButtons();
Expand Down
Loading