diff --git a/memento-note/components/tiptap-outline-extension.tsx b/memento-note/components/tiptap-outline-extension.tsx index 6ba297f..8603a2c 100644 --- a/memento-note/components/tiptap-outline-extension.tsx +++ b/memento-note/components/tiptap-outline-extension.tsx @@ -1,5 +1,6 @@ 'use client' +import { useState, useEffect, useRef } from 'react' import { Node, mergeAttributes } from '@tiptap/core' import { ReactNodeViewRenderer, NodeViewWrapper } from '@tiptap/react' import { List, X } from 'lucide-react' @@ -37,7 +38,14 @@ function collectHeadings(editor: Editor): HeadingEntry[] { const OutlineView = ({ editor, deleteNode }: any) => { const { t } = useLanguage() - const headings = collectHeadings(editor as Editor) + const [headings, setHeadings] = useState(() => collectHeadings(editor as Editor)) + + // Re-collect headings when the editor content changes + useEffect(() => { + const update = () => setHeadings(collectHeadings(editor as Editor)) + editor.on('update', update) + return () => { editor.off('update', update) } + }, [editor]) const scrollToHeading = (pos: number) => { const docSize = editor.state.doc.content.size