facebook / lexical

Lexical is an extensible text editor framework that provides excellent reliability, accessibility and performance.
https://lexical.dev
MIT License
17.5k stars 1.45k forks source link

Fix table of contents for headings in tables and collapsible sections #5946

Closed KatsiarynaDzibrova closed 2 weeks ago

KatsiarynaDzibrova commented 3 weeks ago

Fixes following issues with table of contents:

Now on each heading update dfs is used to get all headings and create a new TOC from scratch. It might take more time, but the change shouldn't be noticeable

Before: toc-before

After: toc-after

vercel[bot] commented 3 weeks ago

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
lexical ✅ Ready (Inspect) Visit Preview 💬 Add feedback Apr 29, 2024 3:43pm
lexical-playground ✅ Ready (Inspect) Visit Preview 💬 Add feedback Apr 29, 2024 3:43pm
KatsiarynaDzibrova commented 2 weeks ago

Made the following changes:

  1. Explicitly checking if the heading is already in TOC to avoid duplicates
  2. Replaced dfs with listener on root updates, which updates all child headings
  3. Find previous heading for a new heading only when it's updated The performance should be much better now as we only visit updated nodes

@zurfyx feel free to take a look