From 359c2b769048ecf3bd3c87ef48cb045d077ae2c0 Mon Sep 17 00:00:00 2001 From: bincxz <16399091+binaricat@users.noreply.github.com> Date: Mon, 24 Aug 2026 18:42:54 +0800 Subject: [PATCH] fix(notes): address latest review findings --- components/notes/NotesManager.test.tsx | 2 ++ components/notes/NotesManager.tsx | 4 ++-- domain/notes.test.ts | 12 ++++++++++++ domain/notes.ts | 24 ++---------------------- 4 files changed, 18 insertions(+), 24 deletions(-) diff --git a/components/notes/NotesManager.test.tsx b/components/notes/NotesManager.test.tsx index e6626ae3d..d1681c55c 100644 --- a/components/notes/NotesManager.test.tsx +++ b/components/notes/NotesManager.test.tsx @@ -354,4 +354,6 @@ test("NotesManager can re-open the same sidebar note when the request id changes assert.match(source, /openNoteRequestId\?: number \| null/); assert.match(source, /\[isSidebarMode, onOpenNoteIdHandled, openNoteId, openNoteRequestId, sortedNotes\]/); + assert.match(source, /if \(isSidebarMode && overlayNoteView\)/); + assert.match(source, /\[isSidebarMode, overlayNoteView\]/); }); diff --git a/components/notes/NotesManager.tsx b/components/notes/NotesManager.tsx index 2f539a694..b173ab45b 100644 --- a/components/notes/NotesManager.tsx +++ b/components/notes/NotesManager.tsx @@ -743,12 +743,12 @@ export const NotesManager: React.FC = ({ const overlayEditorRef = useRef(null); const handleToolbarAction = useCallback((action: MarkdownActionType) => { - if (overlayNoteView) { + if (isSidebarMode && overlayNoteView) { overlayEditorRef.current?.executeAction(action); } else { inlineEditorRef.current?.executeAction(action); } - }, [overlayNoteView]); + }, [isSidebarMode, overlayNoteView]); const handleOutlineHeadingSelect = useCallback((heading: NoteHeadingItem, index: number) => { inlineEditorRef.current?.scrollToHeading(heading, index); diff --git a/domain/notes.test.ts b/domain/notes.test.ts index 6db92a05c..936665041 100644 --- a/domain/notes.test.ts +++ b/domain/notes.test.ts @@ -208,10 +208,22 @@ test("deriveNoteImportTitle prefers the first markdown heading", () => { deriveNoteImportTitle("script.md", "```sh\n# not a title\n```\n\n# Real Title"), "Real Title", ); + assert.equal( + deriveNoteImportTitle("tilde.md", "~~~md\n# not a title\n~~~\n\n# Tilde Fence Title"), + "Tilde Fence Title", + ); + assert.equal( + deriveNoteImportTitle("long-fence.md", "````md\n# not a title\n```\nstill fenced\n````\n\n# Long Fence Title"), + "Long Fence Title", + ); assert.equal( deriveNoteImportTitle("unclosed.md", "```sh\n# not a title\n\n# Also inside fence"), "unclosed", ); + assert.equal( + deriveNoteImportTitle("unclosed-tilde.md", "~~~sh\n# not a title\n\n# Also inside fence"), + "unclosed-tilde", + ); assert.equal( deriveNoteImportTitle("preface.md", "# Real Title\n\n```sh\n# not a title"), "Real Title", diff --git a/domain/notes.ts b/domain/notes.ts index b86b3ab13..b0b3de24d 100644 --- a/domain/notes.ts +++ b/domain/notes.ts @@ -361,29 +361,9 @@ export const resolveRenderedMarkdownLinkHref = ( const NOTE_IMPORT_TITLE_EXTENSIONS = /\.(md|markdown|txt)$/i; -const stripFencedCodeBlocksForImportTitle = (content: string): string => { - const withoutClosedBlocks = content.replace(/```[\s\S]*?```/g, ""); - const lines = withoutClosedBlocks.split("\n"); - const output: string[] = []; - let inUnclosedFence = false; - - for (const line of lines) { - const trimmed = line.trim(); - if (/^```/.test(trimmed)) { - inUnclosedFence = true; - continue; - } - if (inUnclosedFence) continue; - output.push(line); - } - - return output.join("\n"); -}; - export const deriveNoteImportTitle = (fileName: string, content: string): string => { - const contentWithoutCodeBlocks = stripFencedCodeBlocksForImportTitle(content); - const headingMatch = /^#\s+(.+?)\s*$/m.exec(contentWithoutCodeBlocks); - if (headingMatch?.[1]) return headingMatch[1].trim(); + const heading = extractNoteHeadings(content).find((item) => item.level === 1); + if (heading) return heading.text; const baseName = fileName.replace(NOTE_IMPORT_TITLE_EXTENSIONS, "").trim(); return baseName || "Untitled note";