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
23 changes: 23 additions & 0 deletions apps/desktop/src/preview/PickPreload.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,16 @@ const MAX_MARQUEE_ELEMENTS = 20;
const ELEMENT_CONTEXT_TIMEOUT_MS = 5_000;
const CONTENT_LAYER_Z_INDEX = 1;
const CHROME_LAYER_Z_INDEX = 10;
// Page dialogs (Radix, react-remove-scroll) dismiss, refocus or block scrolling on document events
// that shadow retargeting attributes to the overlay host.
const PAGE_ISOLATED_EVENTS = [
"pointerdown",
"focusin",
"focusout",
"wheel",
"touchstart",
"touchmove",
] as const;

let recordingCursor: ReturnType<typeof installRecordingCursor> | null = null;
ipcRenderer.on(
Expand Down Expand Up @@ -1314,6 +1324,13 @@ function startAnnotation(sendEnabled: boolean): void {
event.stopPropagation();
};

const stopAtOverlay = (event: Event): void => event.stopPropagation();
// Focus moving from the page into the overlay targets the page element, so the host never sees it.
const onFocusOutToOverlay = (event: FocusEvent): void => {
if (event.relatedTarget instanceof Element && isAnnotationNode(event.relatedTarget))
event.stopPropagation();
};

const onPointerOut = (event: PointerEvent): void => {
if (event.relatedTarget === null) clearHoverOutline();
};
Expand Down Expand Up @@ -1351,6 +1368,8 @@ function startAnnotation(sendEnabled: boolean): void {
dragHandle.removeEventListener("pointermove", onEditorPointerMove);
dragHandle.removeEventListener("pointerup", onEditorPointerUp);
dragHandle.removeEventListener("pointercancel", onEditorPointerUp);
for (const type of PAGE_ISOLATED_EVENTS) host.removeEventListener(type, stopAtOverlay);
document.documentElement.removeEventListener("focusout", onFocusOutToOverlay);
if (editorLayoutFrame !== null) window.cancelAnimationFrame(editorLayoutFrame);
ipcRenderer.off(CANCEL_PICK_CHANNEL, onCancel);
ipcRenderer.off(ANNOTATION_CAPTURED_CHANNEL, onCaptured);
Expand Down Expand Up @@ -1463,6 +1482,10 @@ function startAnnotation(sendEnabled: boolean): void {
window.addEventListener("keydown", onKeyDown, { capture: true });
window.addEventListener("scroll", repaint, { capture: true, passive: true });
window.addEventListener("resize", repaint, { passive: true });
// Bubble phase, so the overlay's own handlers still see these events.
for (const type of PAGE_ISOLATED_EVENTS)
host.addEventListener(type, stopAtOverlay, { passive: true });
document.documentElement.addEventListener("focusout", onFocusOutToOverlay);
ipcRenderer.on(CANCEL_PICK_CHANNEL, onCancel);
ipcRenderer.on(ANNOTATION_CAPTURED_CHANNEL, onCaptured);
if (inputLayer) {
Expand Down
Loading