Skip to content

Commit

Permalink
ensure we capture events in selection menu handlers (#8096)
Browse files Browse the repository at this point in the history
  • Loading branch information
fungairino authored and grahamlangford committed Mar 29, 2024
1 parent 75cee1c commit 76a5a79
Showing 1 changed file with 12 additions and 6 deletions.
18 changes: 12 additions & 6 deletions src/contentScript/textSelectionMenu/selectionMenuController.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -48,12 +48,6 @@ export const selectionMenuActionRegistry = new ActionRegistry();

let selectionMenu: Nullishable<HTMLElement>;

const onMousedownHide = (event: MouseEvent) => {
if (event.target instanceof Node && !selectionMenu?.contains(event.target)) {
hideSelectionMenu();
}
};

/**
* AbortController fired when the popover is hidden/destroyed.
*/
Expand Down Expand Up @@ -103,6 +97,7 @@ async function showSelectionMenu(): Promise<void> {
passive: true,
once: true,
signal: hideController.signal,
capture: true,
},
);
}
Expand All @@ -116,12 +111,23 @@ async function showSelectionMenu(): Promise<void> {
passive: true,
once: true,
signal: hideController.signal,
capture: true,
});
}

const onMousedownHide = (event: MouseEvent) => {
if (
event.target instanceof Node &&
!selectionMenu?.contains(event.target)
) {
hideSelectionMenu();
}
};

document.addEventListener("mousedown", onMousedownHide, {
passive: true,
signal: hideController.signal,
capture: true,
});

return updatePosition();
Expand Down

0 comments on commit 76a5a79

Please sign in to comment.