mirror of
https://github.com/binaricat/Netcatty.git
synced 2026-11-19 22:45:45 +00:00
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
This commit is contained in:
2 files changed
+21
-1
No files matched your search
@@ -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<HTMLElement \| null>\(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");
|
||||
|
||||
|
||||
@@ -946,6 +946,14 @@ export const InlineMarkdownEditor = React.memo(
|
||||
});
|
||||
|
||||
const containerRef = useRef<HTMLDivElement>(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<HTMLElement | null>(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 (
|
||||
<div
|
||||
ref={containerRef}
|
||||
ref={setEditorContainer}
|
||||
className="relative flex h-full flex-col"
|
||||
style={{
|
||||
["--note-font-family" as string]: noteFontFamily || undefined,
|
||||
@@ -2223,6 +2231,7 @@ export const InlineMarkdownEditor = React.memo(
|
||||
<MDXEditor
|
||||
key={editorMode}
|
||||
ref={editorRef}
|
||||
overlayContainer={overlayContainer ?? undefined}
|
||||
markdown={
|
||||
mdxRetry !== null && value === mdxRetry.staleValue
|
||||
? normalizeNotePublicAssetPaths(mdxRetry.markdown)
|
||||
|
||||
Reference in new issue
Block a user