Keep the tree expansion state when refreshing the JSON tree - #252
Open
leoshone wants to merge 1 commit into
Open
Keep the tree expansion state when refreshing the JSON tree#252leoshone wants to merge 1 commit into
leoshone wants to merge 1 commit into
Conversation
"Refresh JSON Tree" rebuilds every node, so the tree always came back fully collapsed - even when the user only wanted to re-read a document they were already looking at. Capture which nodes are expanded and which one is selected before the tree is thrown away, then re-apply that state onto the freshly built tree, matching nodes by path. Paths that no longer exist (the document changed in the meantime) are silently dropped, and nodes that are new stay collapsed. The state is keyed by node path, which is the list of keys from the tree root down to a node. The pure path arithmetic lives in the new TreeExpansion.h/.cpp so it can be unit tested without a window. DrawJsonTree() gained a bPreserveExpansion parameter that defaults to false, so every other caller (panel opening, formatting, compressing, sorting) keeps behaving exactly as before; only the refresh button opts in.
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.
Problem
"Refresh JSON Tree" rebuilds every node, so the tree always comes back fully
collapsed. Re-reading a document you were already looking at means rebuilding
the expansion by hand every time, which makes the button impractical on a
larger file.
Steps to reproduce
Fix
Capture which nodes are expanded and which one is selected before the tree is
rebuilt, then re-apply that state onto the new tree, matching nodes by path.
(
nested.deep.flag), so it survives the tree being rebuilt from scratch.silently discarded, and nodes that are new simply stay collapsed.
TreeExpansion.h/.cppso thatit can be unit tested without a window.
Notes
DrawJsonTree()gained abPreserveExpansionparameter that defaults tofalse. Every other caller (panel opening, format, compress, sort) keeps
behaving exactly as before; only the refresh button opts in.
code in
JsonViewDlg, so whichever merges second may need a trivial rebase.Tests
tests/UnitTest/TreeExpansionTest.cpp- 14 cases over the three pure helpers:path splitting/joining, and which paths must be re-expanded versus dropped.
Verified by hand on a portable Notepad++: expanding two levels and selecting a
node survives a refresh byte-for-byte, and - importantly - collapsing a node
and refreshing leaves it collapsed, so this is not simply "expand everything".