Skip to content

Commit 81bc127

Browse files
fix(desktop): allow browser annotations over native modal dialogs
Show the annotation overlay as a manual top-layer popover inside the active native modal so its editor can receive input. Move it when dialogs change and disconnect the observer when the annotation session ends.
1 parent 7812230 commit 81bc127

1 file changed

Lines changed: 28 additions & 2 deletions

File tree

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

Lines changed: 28 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -517,7 +517,8 @@ function startAnnotation(): void {
517517
let finished = false;
518518
const host = document.createElement("div");
519519
host.setAttribute(OVERLAY_ATTRIBUTE, "");
520-
host.style.cssText = `position:fixed;inset:0;z-index:${Z_INDEX_OVERLAY};pointer-events:none`;
520+
host.popover = "manual";
521+
host.style.cssText = `position:fixed;inset:0;width:100%;height:100%;margin:0;padding:0;border:0;background:transparent;overflow:visible;z-index:${Z_INDEX_OVERLAY};pointer-events:none`;
521522
applyAnnotationTheme(host, annotationTheme);
522523
const shadowRoot = host.attachShadow({ mode: "closed" });
523524
const themeStyle = document.createElement("style");
@@ -1319,6 +1320,7 @@ function startAnnotation(): void {
13191320
if (editorLayoutFrame !== null) window.cancelAnimationFrame(editorLayoutFrame);
13201321
ipcRenderer.off(CANCEL_PICK_CHANNEL, onCancel);
13211322
ipcRenderer.off(ANNOTATION_CAPTURED_CHANNEL, onCaptured);
1323+
modalObserver.disconnect();
13221324
document.documentElement.removeAttribute("data-t3code-annotation-tool");
13231325
cursorStyle.remove();
13241326
host.remove();
@@ -1427,7 +1429,31 @@ function startAnnotation(): void {
14271429
window.addEventListener("resize", repaint, { passive: true });
14281430
ipcRenderer.on(CANCEL_PICK_CHANNEL, onCancel);
14291431
ipcRenderer.on(ANNOTATION_CAPTURED_CHANNEL, onCaptured);
1430-
document.documentElement.appendChild(host);
1432+
const syncOverlay = (): void => {
1433+
// A modal makes the rest of the document inert. Keep the top-layer overlay
1434+
// inside it so the editor stays interactive, including when dialogs change.
1435+
const modal = document.elementFromPoint(0, 0)?.closest("dialog:modal");
1436+
const parent = modal ?? document.documentElement;
1437+
if (host.parentElement === parent) return;
1438+
parent.appendChild(host);
1439+
host.showPopover();
1440+
};
1441+
const modalObserver = new MutationObserver((records) => {
1442+
if (
1443+
!host.isConnected ||
1444+
records.some(
1445+
(record) => record.type === "attributes" && record.target instanceof HTMLDialogElement,
1446+
)
1447+
)
1448+
syncOverlay();
1449+
});
1450+
syncOverlay();
1451+
modalObserver.observe(document.documentElement, {
1452+
attributes: true,
1453+
attributeFilter: ["open"],
1454+
childList: true,
1455+
subtree: true,
1456+
});
14311457
refreshToolButtons();
14321458
updateStatus();
14331459
activeSession = {

0 commit comments

Comments
 (0)