Skip to content

Commit e26decd

Browse files
thatsnoiclaude
andauthored
fix(desktop): annotating inside a page's dialog no longer closes it (pingdotgg#29287)
Co-authored-by: Claude Opus 5.5 <[email protected]>
1 parent 220a743 commit e26decd

1 file changed

Lines changed: 23 additions & 0 deletions

File tree

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

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,16 @@ const MAX_MARQUEE_ELEMENTS = 20;
4949
const ELEMENT_CONTEXT_TIMEOUT_MS = 5_000;
5050
const CONTENT_LAYER_Z_INDEX = 1;
5151
const CHROME_LAYER_Z_INDEX = 10;
52+
// Page dialogs (Radix, react-remove-scroll) dismiss, refocus or block scrolling on document events
53+
// that shadow retargeting attributes to the overlay host.
54+
const PAGE_ISOLATED_EVENTS = [
55+
"pointerdown",
56+
"focusin",
57+
"focusout",
58+
"wheel",
59+
"touchstart",
60+
"touchmove",
61+
] as const;
5262

5363
let recordingCursor: ReturnType<typeof installRecordingCursor> | null = null;
5464
ipcRenderer.on(
@@ -1549,6 +1559,13 @@ function startAnnotation(
15491559
event.stopPropagation();
15501560
};
15511561

1562+
const stopAtOverlay = (event: Event): void => event.stopPropagation();
1563+
// Focus moving from the page into the overlay targets the page element, so the host never sees it.
1564+
const onFocusOutToOverlay = (event: FocusEvent): void => {
1565+
if (event.relatedTarget instanceof Element && isAnnotationNode(event.relatedTarget))
1566+
event.stopPropagation();
1567+
};
1568+
15521569
const onPointerOut = (event: PointerEvent): void => {
15531570
if (event.relatedTarget === null) clearHoverOutline();
15541571
};
@@ -1592,6 +1609,8 @@ function startAnnotation(
15921609
dragHandle.removeEventListener("pointermove", onEditorPointerMove);
15931610
dragHandle.removeEventListener("pointerup", onEditorPointerUp);
15941611
dragHandle.removeEventListener("pointercancel", onEditorPointerUp);
1612+
for (const type of PAGE_ISOLATED_EVENTS) host.removeEventListener(type, stopAtOverlay);
1613+
document.documentElement.removeEventListener("focusout", onFocusOutToOverlay);
15951614
if (editorLayoutFrame !== null) window.cancelAnimationFrame(editorLayoutFrame);
15961615
ipcRenderer.off(CANCEL_PICK_CHANNEL, onCancel);
15971616
ipcRenderer.off(ANNOTATION_CAPTURED_CHANNEL, onCaptured);
@@ -1743,6 +1762,10 @@ function startAnnotation(
17431762
window.addEventListener("keyup", onVoiceKeyUp, { capture: true });
17441763
window.addEventListener("scroll", repaint, { capture: true, passive: true });
17451764
window.addEventListener("resize", repaint, { passive: true });
1765+
// Bubble phase, so the overlay's own handlers still see these events.
1766+
for (const type of PAGE_ISOLATED_EVENTS)
1767+
host.addEventListener(type, stopAtOverlay, { passive: true });
1768+
document.documentElement.addEventListener("focusout", onFocusOutToOverlay);
17461769
ipcRenderer.on(CANCEL_PICK_CHANNEL, onCancel);
17471770
ipcRenderer.on(ANNOTATION_CAPTURED_CHANNEL, onCaptured);
17481771
if (voice) ipcRenderer.on(ANNOTATION_VOICE_STATE_CHANNEL, onVoiceState);

0 commit comments

Comments
 (0)