Skip to content

Persist the tree view zoom level across Notepad++ sessions - #2

Draft
leoshone wants to merge 2 commits into
masterfrom
fix/persist-tree-zoom
Draft

Persist the tree view zoom level across Notepad++ sessions#2
leoshone wants to merge 2 commits into
masterfrom
fix/persist-tree-zoom

Conversation

@leoshone

@leoshone leoshone commented Sep 3, 2026

Copy link
Copy Markdown
Owner

Problem

The JSON tree already has a zoom slider (80%..250%, plus Ctrl+MouseWheel over
the panel), but the chosen level is not remembered: after restarting Notepad++
the tree is always back at 100%.

Steps to reproduce

  1. Open a .json file and show the JSON Viewer panel.
  2. Drag the zoom slider to 150% (or Ctrl+wheel).
  3. Restart Notepad++ and show the panel again.
  4. The tree renders at 100% while the slider thumb and the percent label still
    say 150%, until the slider is touched again.

Cause

Setting had no field for the zoom level, so ProfileSetting::GetSettings()
and SetSettings() had nothing to read or write. The level only ever lived in
the trackbar control.

Fix

  • Setting::nTreeZoom (default 100) plus a new [Others] TREE_ZOOM key in
    JSONViewer.ini, read and written exactly like the neighbouring keys.
  • JsonViewDlg::PersistZoom() writes the value when it changes.
  • WM_INITDIALOG re-applies the level that was read from the ini.
  • While the slider thumb is being dragged (TB_THUMBTRACK) nothing is written,
    so one gesture produces one write instead of one per pixel.

Notes

  • Purely additive: no existing ini key renamed or removed, no default behaviour
    changed, no resource or UI change.
  • An existing JSONViewer.ini simply has no TREE_ZOOM key and falls back to
    100%.

Tests

tests/UnitTest/ProfileTest.cpp

  • TreeZoom_RoundTrip - default is 100%, and 80/100/150/200/250 survive a
    write/read cycle.
  • SetSettings_Positive - extended to cover the new field.

The plugin already ships a zoom slider for the JSON tree (80%..250%),
but the chosen level only lived in the slider control: closing
Notepad++ and starting it again always fell back to 100%.

Store the zoom percentage in JSONViewer.ini under [Others] TREE_ZOOM
and re-apply it when the dialog is initialised.

The value is written only when it actually changes, and while the
slider thumb is being dragged (TB_THUMBTRACK) nothing is written, so
a drag gesture produces a single write at the end instead of one per
pixel.

Purely additive: the existing ini keys and the default behaviour are
untouched.
@leoshone
leoshone force-pushed the fix/persist-tree-zoom branch from 31fd4f1 to 05c1128 Compare September 3, 2026 10:18
WM_HSCROLL carries the notification code in LOWORD(wParam), not HIWORD: HIWORD holds the thumb position itself (80..250 here), so comparing it against TB_THUMBTRACK never matched and the zoom was written to the ini file continuously while the thumb was being dragged, instead of once when the gesture ended.

Found by an independent review of the integration branch; the end-to-end harness never caught it because it only sends TB_ENDTRACK and never simulates the dragging itself.
@leoshone
leoshone force-pushed the fix/persist-tree-zoom branch from 16bad52 to 7771ca0 Compare September 5, 2026 04:15
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