Repository navigation
Keep a DiffView hunk's collapse with that hunk, not its position [patch] - #632
Merged
Merged
Conversation
DiffViewState kept collapsed hunks as a set of indices that lived as long as the widget's label. Selecting another file under the same label, or re-reading a diff after staging a hunk, put new hunks at old positions and they opened collapsed. The flag now lives on the per-hunk layout, which is already replaced when a different hunk instance arrives at a position, so a new hunk starts expanded and a redrawn one keeps its state. Fixes #482 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01JrNRgZ65vSm9BQxYHcanRS
|
This was referenced Oct 14, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.



Fixes #482
What was wrong
DiffViewStatestored collapsed hunks as aHashSet<int>of positions. That state lives as long as the widget's label, so:Change
This follows the issue's preferred fix. The collapse flag is now a
Collapsedproperty onHunkLayout.LayoutForalready replaces a layout when a different hunk instance arrives at a position (!ReferenceEquals(layout.Hunk, hunk)), so:IsCollapsedandToggleCollapsednow take the hunk as well as the index. Both are internal, andDiffView's three call sites already have the hunk in scope. TheHashSet<int>is gone.The issue's optional suggestion was left out on purpose: the static
Statesdictionary is still never evicted. It grows only per distinct label, and nothing in this PR adds to it.Tests
DiffViewStateTests:Collapse_ADifferentHunkAtTheSamePosition_StartsExpandedis the bug. Temporarily switching the state back to index-only storage makes it fail, and it passes with the fix.Collapse_TheSameHunkAgain_StaysCollapsedcovers the issue's second requested case.Collapse_OtherPositions_AreUnaffectedchecks that collapsing one position leaves the others alone.Collapse_ToggledTwice_ReturnsToExpandedis updated for the new signature.Results:
ImGui.Widgets.Tests: 1126/1126 pass.dotnet build ImGui.Widgetsacross all target frameworks: 0 warnings, 0 errors.🤖 Generated with Claude Code
https://claude.ai/code/session_01JrNRgZ65vSm9BQxYHcanRS
Generated by Claude Code