diff --git a/apps/roam/src/components/DiscourseNodeMenu.tsx b/apps/roam/src/components/DiscourseNodeMenu.tsx index 5729e6f8b..e3a544ef4 100644 --- a/apps/roam/src/components/DiscourseNodeMenu.tsx +++ b/apps/roam/src/components/DiscourseNodeMenu.tsx @@ -100,6 +100,8 @@ const NodeMenu = ({ const keydownListener = useCallback( (e: KeyboardEvent) => { + if (e.metaKey || e.ctrlKey || e.shiftKey) return; + if (e.key === "ArrowDown") { const index = Number( menuRef.current?.getAttribute("data-active-index"), diff --git a/apps/roam/src/utils/initializeObserversAndListeners.ts b/apps/roam/src/utils/initializeObserversAndListeners.ts index feaf6a337..5dbe495a1 100644 --- a/apps/roam/src/utils/initializeObserversAndListeners.ts +++ b/apps/roam/src/utils/initializeObserversAndListeners.ts @@ -257,7 +257,10 @@ export const initObservers = async ({ const selection = window.getSelection(); - if (!selection || selection.rangeCount === 0) return; + if (!selection || selection.rangeCount === 0 || !selection.focusNode) { + removeTextSelectionPopup(); + return; + } const selectedText = selection.toString().trim(); diff --git a/apps/roam/src/utils/renderTextSelectionPopup.tsx b/apps/roam/src/utils/renderTextSelectionPopup.tsx index de172b13d..3514ec3de 100644 --- a/apps/roam/src/utils/renderTextSelectionPopup.tsx +++ b/apps/roam/src/utils/renderTextSelectionPopup.tsx @@ -65,9 +65,9 @@ export const renderTextSelectionPopup = ({ }; export const removeTextSelectionPopup = () => { - if (currentPopupContainer) { - ReactDOM.unmountComponentAtNode(currentPopupContainer); - currentPopupContainer.remove(); - currentPopupContainer = null; + const container = document.getElementById("discourse-text-selection-popup"); + if (container) { + ReactDOM.unmountComponentAtNode(container); + container.remove(); } };