Skip to content

SD-2664 - feature support word style update field interactions for TOC#3120

Open
chittolinag wants to merge 15 commits intomainfrom
gabriel/sd-2664-feature-support-word-style-update-field-interactions-for
Open

SD-2664 - feature support word style update field interactions for TOC#3120
chittolinag wants to merge 15 commits intomainfrom
gabriel/sd-2664-feature-support-word-style-update-field-interactions-for

Conversation

@chittolinag
Copy link
Copy Markdown
Contributor

@chittolinag chittolinag commented May 4, 2026

Issue

Word-style "Update Field" interactions (context menu + F9) aren't wired up in SuperDoc. The document API already exposes editor.doc.toc.update(), but no user-facing action calls it. Scope of this PR is Table of Contents only — other field types are deferred.

Proposed solution

  • Right-click → "Update table of contents" when the cursor is inside a TOC.
  • F9 rebuilds every TOC in the document.
  • Fixed a handful of issues in the rebuild path that surfaced once the action was actually exercised end-to-end (font/style preservation, dot leader, spacing, pasted-heading detection).
  • Added unit tests for the context-menu item, the F9 command, and the rebuild helpers, plus a behavior test that loads a TOC docx, presses F9, and verifies the rebuilt entries match the document's headings.

@linear
Copy link
Copy Markdown

linear Bot commented May 4, 2026

@codecov-commenter
Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.

📢 Thoughts on this report? Let us know!

@chittolinag chittolinag marked this pull request as ready for review May 4, 2026 20:25
@chittolinag chittolinag requested a review from a team as a code owner May 4, 2026 20:25
@chittolinag chittolinag changed the title SD-2664 - feature support word style update field interactions for SD-2664 - feature support word style update field interactions for TOC May 4, 2026
- tabLeader: 'none' must round-trip via serialize/parse (currently lost
  because no \\p is emitted when separator is missing, and the parser has
  no way to disambiguate "default = dots" from "explicit none").
- toc.configure({ tabLeader: 'none' }) on a default-leader TOC must not
  silently no-op (areTocConfigsEqual reports identical serialized output).
- toc.update mode: 'pageNumbers' must find tocPageNumber marks when the
  marked text is nested inside a run wrapper (the rebuild output shape).

All three tests fail on the current branch and lock in the regressions
flagged in code review.
Copy link
Copy Markdown
Contributor

@caio-pizzol caio-pizzol left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

hey @chittolinag! the \p fix is the right call, but the rebuild path is regressing in a few spots.

pushed bceff5248 - three failing tests for findings 1, 1b, and 2.

left a few inline.

needs work.

*/
function deriveTabLeader(separator: string | undefined): TocDisplayConfig['tabLeader'] | undefined {
if (!separator) return 'none';
if (separator === undefined) return undefined;
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

repro: open a TOC with a hyphen leader → editor.doc.toc.configure({ target, patch: { tabLeader: 'none' } })toc.update({ target, mode: 'all' }). the rebuilt TOC comes back with dots, not none. on a TOC that already has no leader, configure does nothing - the stored text doesn't change. fix: write \p "" for explicit none, or store the choice in a separate field.

function readExistingTocEntryTextMarks(node: ProseMirrorNode): EntryTextMark[] {
let marks: EntryTextMark[] = [];
node.forEach((paragraph) => {
if (marks.length > 0 || paragraph.type.name !== 'paragraph') return;
Copy link
Copy Markdown
Contributor

@caio-pizzol caio-pizzol May 6, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

repro: open word-fixture-pr-312-bold.docx
(first entry is bold), right-click → "Update table of contents". every entry comes out bold. Word resets to the linked paragraph styles (TOC1, TOC2, …) instead of copying from the first entry - probably the simpler match.

if (tocTargets.length > 0) {
if (!dispatch) return true; // can()-style probe

for (const sdBlockId of tocTargets) {
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

repro: doc with two or more TOCs, press F9. first TOC gets real page numbers, the rest rebuild as 0. each toc.update swaps editor.state.doc, so getPageMap rejects the stored map on the next iteration. fix: grab the page map once before the loop, or batch all updates into one transaction.

@chittolinag chittolinag requested a review from caio-pizzol May 7, 2026 20:02
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants