fix: Outline se met à jour en temps réel quand les titres changent
Ajout d'un listener editor.on('update') dans OutlineView.
Avant: le sommaire était figé au moment de l'insertion.
Maintenant: il se recalcule à chaque ajout/modif/suppression de titre.
This commit is contained in:
@@ -1,5 +1,6 @@
|
|||||||
'use client'
|
'use client'
|
||||||
|
|
||||||
|
import { useState, useEffect, useRef } from 'react'
|
||||||
import { Node, mergeAttributes } from '@tiptap/core'
|
import { Node, mergeAttributes } from '@tiptap/core'
|
||||||
import { ReactNodeViewRenderer, NodeViewWrapper } from '@tiptap/react'
|
import { ReactNodeViewRenderer, NodeViewWrapper } from '@tiptap/react'
|
||||||
import { List, X } from 'lucide-react'
|
import { List, X } from 'lucide-react'
|
||||||
@@ -37,7 +38,14 @@ function collectHeadings(editor: Editor): HeadingEntry[] {
|
|||||||
|
|
||||||
const OutlineView = ({ editor, deleteNode }: any) => {
|
const OutlineView = ({ editor, deleteNode }: any) => {
|
||||||
const { t } = useLanguage()
|
const { t } = useLanguage()
|
||||||
const headings = collectHeadings(editor as Editor)
|
const [headings, setHeadings] = useState<HeadingEntry[]>(() => 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 scrollToHeading = (pos: number) => {
|
||||||
const docSize = editor.state.doc.content.size
|
const docSize = editor.state.doc.content.size
|
||||||
|
|||||||
Reference in New Issue
Block a user