Add expandAll/collapseAll to diffs#349
Add expandAll/collapseAll to diffs#349atamarzban wants to merge 3 commits intopierrecomputer:mainfrom
Conversation
Adds an `allExpanded` flag to the renderer that, when set, passes `expandedHunks: true` to `iterateOverDiff` — expanding all collapsed "N unmodified lines" sections without mutating the per-hunk map. New methods: `expandAll()`, `collapseAll()`, `isAllExpanded()`. State is reset on `cleanUp()` and `recycle()`. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Adds public `expandAll()` and `collapseAll()` methods to `FileDiff`,
`VirtualizedFileDiff`, and the React `useFileDiffInstance` hook.
Also adds a text toggle button ("Expand all" / "Collapse all") in the
file header, next to the filename. The button is visible by default and
can be disabled with `disableExpandAllButton: true`. It is automatically
hidden when `expandUnchanged` or `disableFileHeader` is set.
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Adds 7 unit tests covering expand, collapse, split mode, round-trip, and equivalence with the `expandUnchanged` option. Updates existing snapshots to reflect the new expand-all-button slot in the file header HAST. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
|
@atamarzban is attempting to deploy a commit to the Pierre Computer Company Team on Vercel. A member of the Team first needs to authorize it. |
|
@amadeus Would appreciate a review! 🙏 |
|
Question on this -- shouldn't you be able to accomplish this functionality already with toggling the It's not the cleanest, but right now in the VanillaJS api you could accomplish it with: const diff = new FileDiff(options);
diff.setOptions({ ...diff.options, expandUnchanged: true })
diff.setOptions({ ...diff.options, expandUnchanged: false })
// and in react, you would pass in the prop change to options:
<FileDiff
// ...
options={{ expandUnchanged: true }}
/>
<FileDiff
// ...
options={{ expandUnchanged: false }}
/> |
|
Also, sorry for the delays on this, been traveling a bunch lately so catching up when i can. |
|
@amadeus thx for the taking a look! setOptions with expandUnchanged does cover the basic expand/collapse toggle. The main thing this PR adds is the built-in header button (next to the filename, similar to GitHub). Since it lives inside the shadow DOM, it’s not something consumers can easily wire up themselves, so having it built-in felt worthwhile. There’s also a subtle behavioral difference: collapseAll() clears individually-expanded hunks too, so if someone manually expanded a few sections and then hits “Collapse all”, they get a clean reset. Toggling expandUnchanged back to false would leave those individual expansions intact. That said, the button doesn’t strictly need the new imperative API. It could toggle expandUnchanged internally. The separate methods just make the wiring cleaner. Happy to simplify if you’d prefer a different approach. |
Summary
expandAll()andcollapseAll()methods toFileDiff,VirtualizedFileDiff, and the ReactuseFileDiffInstancehook for controlling collapsed "N unmodified lines" sectionsdisableExpandAllButton: trueexpandUnchangedordisableFileHeaderis setAPI
Vanilla JS:
React:
Disable the built-in button:
🤖 Generated with Claude Code