Skip to content

Persist tree zoom, per-tab tree cache, keep expansion on refresh - #1

Draft
leoshone wants to merge 2 commits into
masterfrom
feature/zoom-persist-tab-snapshot
Draft

Persist tree zoom, per-tab tree cache, keep expansion on refresh#1
leoshone wants to merge 2 commits into
masterfrom
feature/zoom-persist-tab-snapshot

Conversation

@leoshone

@leoshone leoshone commented Sep 3, 2026

Copy link
Copy Markdown
Owner

Three usability fixes for the JSON tree panel.

R1 — Tree zoom is persisted
The sidebar zoom (80%–250%, slider / Ctrl+wheel / double-click reset) now writes
[Others] TREE_ZOOM to JSONViewer.ini and is re-applied on start-up. The
percentage is stored rather than a concrete font size, so the setting survives
DPI changes. Zoom stays a panel-global property, not per tab.

R2 — Nothing is parsed automatically; tree state is cached per tab
Previously the panel either re-parsed on every tab switch (with "Follow current
tab" on) or went stale (with it off). Now:

  • Starting Notepad++, switching tabs and opening files never read the document.
  • Only Refresh JSON Tree parses and draws.
  • Each buffer keeps an in-memory snapshot — node contents, expansion state and
    the selected node — so switching away and back restores the tree exactly as it
    was left, without re-parsing or redrawing.
  • Tabs that were never refreshed show the empty placeholder root (JSON).
  • Snapshots are dropped when a tab is closed and never survive a restart.

R3 — Refresh keeps the expansion state
Refresh rebuilds the tree and then restores the expansion/collapse state and the
selected node by matching node paths; paths that no longer exist are discarded.

Clean-ups

  • Removed the now unused "Follow current tab" setting (UI, INI key and the
    NPPN_READY auto-refresh workaround it needed).
  • Auto-format moved to NPPN_FILEOPENED, so merely switching tabs no longer
    rewrites a document. When it fires it formats the document only — the tree is
    still left alone until the user refreshes.

Testing

  • gtest: 161/161 pass (TreeStateTest is new, ProfileTest extended).
  • End-to-end inside a real Notepad++ instance: 19/19 assertions pass, covering
    no-auto-parse, per-tab snapshot isolation (including two levels of expansion),
    refresh preserving expansion + selection, snapshot dropped on tab close, and
    the zoom round-trip through JSONViewer.ini and a restart.

Note: this branch is on my fork for CI artifacts. Happy to rework anything
before it goes upstream.

R1  Tree zoom (80%-250%) is now written to JSONViewer.ini ([Others]
    TREE_ZOOM) and re-applied on start-up. The percentage is stored, not a
    device-dependent font size, so it survives DPI changes.

R2  The tree is no longer parsed automatically. Opening the panel or
    switching tabs never touches the document; only "Refresh JSON Tree"
    does. Each buffer keeps an in-memory snapshot (node contents,
    expansion state, selected node) that is restored verbatim when the tab
    comes back. Tabs that were never refreshed show the empty placeholder
    root. Snapshots are dropped when a tab is closed.

R3  Refresh rebuilds the tree but restores the expansion state and the
    selected node by matching node paths; paths that no longer exist are
    discarded.

Also removes the now unused "Follow current tab" setting and its
NPPN_READY auto-refresh workaround, and moves auto-format to
NPPN_FILEOPENED so that merely switching tabs never rewrites a document.

Verified locally: gtest 161/161, and 19/19 end-to-end assertions driven
inside a real Notepad++ instance via Window messages.
GitHub Actions was enabled on the fork after the branch and PR were created,
so the original pull_request event was never delivered. An empty commit
emits a synchronize event to start the build.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant