From 8b3832feefbb0742e2f5d31b26a205500ef1d8ef Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=99=88=E5=A4=A7=E7=8C=AB?= <16399091+binaricat@users.noreply.github.com> Date: Tue, 17 Nov 2026 14:53:32 +0800 Subject: [PATCH] fix(notes): keep MDX link dialog inside the editor container (#4258) MDXEditor portals the link preview toolbar to document.body by default. Notes stays retained-mounted and is only CSS-hidden, so the toolbar was left floating over other vault pages and terminal sessions. Fixes #4257 --- components/notes/InlineMarkdownEditor.test.tsx | 11 +++++++++++ components/notes/InlineMarkdownEditor.tsx | 11 ++++++++++- 2 files changed, 21 insertions(+), 1 deletion(-) diff --git a/components/notes/InlineMarkdownEditor.test.tsx b/components/notes/InlineMarkdownEditor.test.tsx index 635d80a5f..31953ea6b 100644 --- a/components/notes/InlineMarkdownEditor.test.tsx +++ b/components/notes/InlineMarkdownEditor.test.tsx @@ -459,6 +459,17 @@ test("note markdown toolbar remains usable in narrow panes", () => { ); }); +test("MDX link dialog overlay stays inside the retained notes editor container", () => { + const source = readFileSync(new URL("./InlineMarkdownEditor.tsx", import.meta.url), "utf8"); + + // Default MDXEditor popup target is document.body. Keep the overlay in the + // editor container so section `hidden` and vault visibility:hidden hide it (#4257). + assert.match(source, /const \[overlayContainer, setOverlayContainer\] = useState\(null\);/); + assert.match(source, /setOverlayContainer\(\(current\) => \(current === node \? current : node\)\);/); + assert.match(source, /ref=\{setEditorContainer\}/); + assert.match(source, /overlayContainer=\{overlayContainer \?\? undefined\}/); +}); + test("preview mode opens links directly without showing the edit hover action", () => { const source = readFileSync(new URL("./InlineMarkdownEditor.tsx", import.meta.url), "utf8"); diff --git a/components/notes/InlineMarkdownEditor.tsx b/components/notes/InlineMarkdownEditor.tsx index fe4cbfbcc..fa6130f2f 100644 --- a/components/notes/InlineMarkdownEditor.tsx +++ b/components/notes/InlineMarkdownEditor.tsx @@ -946,6 +946,14 @@ export const InlineMarkdownEditor = React.memo( }); const containerRef = useRef(null); + // MDXEditor portals .mdxeditor-popup-container to document.body unless + // overlayContainer is set. Notes stays mounted and is only CSS-hidden, so a + // body portal would leave the link preview toolbar over other pages (#4257). + const [overlayContainer, setOverlayContainer] = useState(null); + const setEditorContainer = useCallback((node: HTMLDivElement | null) => { + containerRef.current = node; + setOverlayContainer((current) => (current === node ? current : node)); + }, []); const getSelectedText = useCallback((): string => { const container = containerRef.current; @@ -2063,7 +2071,7 @@ export const InlineMarkdownEditor = React.memo( return (