diff --git a/app/editor/components/SuggestionsMenu.tsx b/app/editor/components/SuggestionsMenu.tsx index 13378cf2f5..051098d575 100644 --- a/app/editor/components/SuggestionsMenu.tsx +++ b/app/editor/components/SuggestionsMenu.tsx @@ -419,7 +419,13 @@ function SuggestionsMenu(props: Props) { const close = React.useCallback(() => { props.onClose(); - view.focus(); + + // Don't steal focus back from a nested editor, such as the one inside a + // math node, that took it while the menu was closing. + const focused = view.dom.ownerDocument.activeElement; + if (focused === view.dom || !view.dom.contains(focused)) { + view.focus(); + } }, [props, view]); const handleLinkInputKeydown = (