diff --git a/web/src/reader/reader.ts b/web/src/reader/reader.ts index 59c2358..aed9b15 100644 --- a/web/src/reader/reader.ts +++ b/web/src/reader/reader.ts @@ -744,6 +744,21 @@ document.addEventListener("alpine:init", () => { () => setTimeout(checkSelection, 0), { passive: true }, ); + // Clicks in the book dismiss the popover in ANY mode: iframe + // events never bubble to the host document (so the host + // outside-click dismiss never sees them), and the collapsed + // check above only covers create mode — edit mode had no + // outside-click path at all, leaving Esc as the only way out. + // Clicking a painted highlight still works: this hides, then + // foliate's show-annotation re-opens it in edit mode. + doc.addEventListener( + "pointerdown", + () => { + if (this.selectionPopover.open) + this.hideSelectionPopover(); + }, + { passive: true }, + ); doc.addEventListener( "keyup", (ev: KeyboardEvent) => {