Skip to content

Commit baf3e88

Browse files
thatsnoiclaude
andcommitted
fix(desktop): annotating inside a page's dialog no longer closes it
The annotation overlay lives in a closed shadow root under <html>, so a page's document listeners see its pointer and focus events as coming from outside any open dialog. Radix popovers closed as soon as the comment field took focus, modal dialogs pulled focus back out of the comment field and closed on toolbar clicks, and react-remove-scroll cancelled wheel events over the editor. Stop pointerdown, focus and wheel/touch events at the overlay host in the bubble phase, after the overlay's own handlers, and stop focusout at <html> when focus moves into the overlay. Co-Authored-By: Claude Opus 5.5 <[email protected]>
1 parent 47f2c8d commit baf3e88

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
@@ -43,6 +43,16 @@ const MAX_MARQUEE_ELEMENTS = 20;
4343
const ELEMENT_CONTEXT_TIMEOUT_MS = 5_000;
4444
const CONTENT_LAYER_Z_INDEX = 1;
4545
const CHROME_LAYER_Z_INDEX = 10;
46+
// Page dialogs (Radix, react-remove-scroll) dismiss, refocus or block scrolling on document events
47+
// that shadow retargeting attributes to the overlay host.
48+
const PAGE_ISOLATED_EVENTS = [
49+
"pointerdown",
50+
"focusin",
51+
"focusout",
52+
"wheel",
53+
"touchstart",
54+
"touchmove",
55+
] as const;
4656

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

1327+
const stopAtOverlay = (event: Event): void => event.stopPropagation();
1328+
// Focus moving from the page into the overlay targets the page element, so the host never sees it.
1329+
const onFocusOutToOverlay = (event: FocusEvent): void => {
1330+
if (event.relatedTarget instanceof Element && isAnnotationNode(event.relatedTarget))
1331+
event.stopPropagation();
1332+
};
1333+
13171334
const onPointerOut = (event: PointerEvent): void => {
13181335
if (event.relatedTarget === null) clearHoverOutline();
13191336
};
@@ -1351,6 +1368,8 @@ function startAnnotation(sendEnabled: boolean): void {
13511368
dragHandle.removeEventListener("pointermove", onEditorPointerMove);
13521369
dragHandle.removeEventListener("pointerup", onEditorPointerUp);
13531370
dragHandle.removeEventListener("pointercancel", onEditorPointerUp);
1371+
for (const type of PAGE_ISOLATED_EVENTS) host.removeEventListener(type, stopAtOverlay);
1372+
document.documentElement.removeEventListener("focusout", onFocusOutToOverlay);
13541373
if (editorLayoutFrame !== null) window.cancelAnimationFrame(editorLayoutFrame);
13551374
ipcRenderer.off(CANCEL_PICK_CHANNEL, onCancel);
13561375
ipcRenderer.off(ANNOTATION_CAPTURED_CHANNEL, onCaptured);
@@ -1463,6 +1482,10 @@ function startAnnotation(sendEnabled: boolean): void {
14631482
window.addEventListener("keydown", onKeyDown, { capture: true });
14641483
window.addEventListener("scroll", repaint, { capture: true, passive: true });
14651484
window.addEventListener("resize", repaint, { passive: true });
1485+
// Bubble phase, so the overlay's own handlers still see these events.
1486+
for (const type of PAGE_ISOLATED_EVENTS)
1487+
host.addEventListener(type, stopAtOverlay, { passive: true });
1488+
document.documentElement.addEventListener("focusout", onFocusOutToOverlay);
14661489
ipcRenderer.on(CANCEL_PICK_CHANNEL, onCancel);
14671490
ipcRenderer.on(ANNOTATION_CAPTURED_CHANNEL, onCaptured);
14681491
if (inputLayer) {

0 commit comments

Comments
 (0)