Skip to content

feat(ui): rebuild the panel UI on a design-token system - #7

Merged
LucianCrainic merged 8 commits into
developfrom
feat/ui-revamp
Aug 14, 2026
Merged

LucianCrainic merged 8 commits into
developfrom
feat/ui-revamp

Conversation

@LucianCrainic

Copy link
Copy Markdown
Owner

Rebuilds JSONBro's UI to read as a native VS Code surface, and refactors the layer underneath so the next UI change is a small diff.

Why

The panel looked like a web app hosted in VS Code rather than part of it: a 48px toolbar of text buttons, 8px card radii, 16px page padding, -apple-system type, and action buttons floating over pane content positioned by hardcoded right: 88px / right: 48px offsets keyed to nth-of-type.

Underneath, all 910 lines of CSS lived in a template literal inside webview-content.ts — unlintable, and one rule was already silently broken (a selector line had gone missing, leaving orphaned declarations). controller.ts was a 1592-line god object owning DOM wiring, mode switching, splitter drag, maximize, search, diff resolution, clipboard and folding.

What changed

Design system. Every colour, font and metric resolves through media/tokens.css. Nothing else references a --vscode-* variable, so retheming happens in one place and no rule can hardcode a colour that breaks in another theme. High-contrast themes override the tokens on body.vscode-high-contrast, reaching every rule without any of them knowing about the theme.

Chrome. Toolbar 36px, pane headers 28px, status bar 22px — VS Code's own heights. Mode switcher restyled after the panel tabs. Pane actions moved into real header bars, retiring the overlay buttons and their offset arithmetic. New status bar (validity, line count, size in Format; counts by change kind in Diff) and an empty state whose keyboard legend resolves the modifier key at runtime, so macOS sees ⌘.

Find. Search moved out of the toolbar — where opening it made the trigger disappear and swap places with the input — into a widget floating over the content it searches. Match-case, regex, and an All/Keys/Values scope row. Term and options survive close and reopen.

Diff. All three panes are now resizable (only Format was before). Change rows render the path as breadcrumb segments with the leaf emphasised and array indices as [0], with the value on its own line. Filter chips with live counts narrow the list. Resolution state is one data-state attribute rather than parallel CSS classes.

Icons. @vscode/codicons replaces every hand-drawn SVG — the maximize path had been duplicated five times in markup plus twice as JS strings, and the check/close/undo trio three times. Zero inline <svg> remain. It is the extension's only runtime dependency.

Structure. controller.ts is gone, replaced by shell.ts, two views and nine ui/ modules, plus a shared/messages.ts contract imported by both bundles.

Bugs fixed along the way

  • Two competing document keydown listeners both claimed Cmd+0 and relied on mode checks to avoid colliding. One registry now dispatches exactly one match.
  • Maximize re-bound its buttons on every mode switch and cloned each node to shed the old listener, silently discarding listeners attached to the button's children.
  • Loading history into a not-yet-created panel posted after a fixed 100ms, dropping the message on a slow load. The webview signals ready and the host queues and flushes.
  • Reject-all never recorded state — only a CSS class — so a later undo on a row behaved as if it had never been rejected.
  • Opening search was a silent no-op until something had been formatted, so on a fresh panel with JSON already pasted the button looked dead.
  • The gutter was searchable: searching 1 lit up line numbers alongside real hits.
  • Find-match colours were swapped, so the active match rendered less prominently than the others.
  • Modified diff rows used diffEditor-border — a line colour — as a background fill, which read as a grey selection band in light themes.
  • Folding was quadratic: each hidden element scanned the whole line list to find its gutter entry. The formatter emits data-line now.
  • Two hardcoded rgba() values, one of which was invisible in dark themes; the panel tab icon's hardcoded #FFA500 and its <text>{}</text> hack, which depended on a monospace font being installed.
  • getNonce used Math.random; localResourceRoots pointed at node_modules, which was never read from.

Notes for review

  • CSP is tighter: style-src dropped 'unsafe-inline' once mode visibility became data-mode on <body> plus CSS. Worth confirming no style="…" sneaks back into generated markup — it would fail silently in the panel but not in tests.
  • The codicon font is copied into media/ at build time rather than referenced from node_modules, because .vscodeignore excludes the latter. If that copy step breaks, the webview ships with no icons. npx vsce ls shows media/codicons/codicon.ttf.
  • diff.test.ts and json-parser.test.ts are untouched — the compare, apply and revert engines were not modified, only how their results are rendered.
  • formatter.test.ts needed updating because it asserts on HTML substrings and the markup changed.
  • Tests: 174 → 266. Jest now runs two projects, node for the engines and jsdom for anything touching the DOM. DOM fixtures are generated from the real WebviewContentGenerator via a stubbed vscode module, so they cannot drift from production markup — a class of bug that bit once during this work.
  • .vscode/launch.json and tasks.json are new; F5 debugging was not set up in this repo before.

Not included

Persistence and settings (webview setState/getState, a panel serializer, contributes.configuration, contributes.keybindings, and backing the sidebar history with globalState) were planned as a sixth phase and are not in this PR. Panel content is still lost on reload, and the seven keyboard shortcuts remain undiscoverable outside the empty state's legend.

Verification

Both views were checked in dark and light themes by rendering the real webview HTML against transcribed VS Code theme variables, and the interactive behaviour — find scoping, regex, invalid patterns, filter chips, splitter composition, apply/reject/undo — was driven live in a browser. Worth a pass in the Extension Development Host across a high-contrast theme before merge, which I could not do from here.

LucianCrainic and others added 8 commits August 2, 2026 23:54
Phase 1 of the UI revamp. Groundwork only -- no redesign yet.

All 910 lines of CSS lived in a template literal in webview-content.ts,
which had no linting and one silently broken rule. Split into five
stylesheets loaded as webview resources:

  tokens.css      design tokens mapped from --vscode-* (unused until phase 3)
  base.css        document shell, buttons, icon sizing
  components.css  toolbar, panes, splitter, overlay controls, notification
  format.css      syntax tokens, gutter, folding, search highlight
  diff.css        diff list, items, actions, resolved states

webview-content.ts drops 1155 -> 273 lines.

Verified with a rule-by-rule parse of the old stylesheet against the new
files: no rule was lost. Removed only dead selectors (.left-preview,
.right-preview, .panel-header, empty #format-container, and the stale
ul/li/.json-array/.json-object/.json-items rules left over from before
the formatter switched to .json-line divs), plus the orphaned
declarations where a selector line had gone missing.

Four deliberate fixes carried along with the move:
- .search-highlight and .current used VS Code's find-match variables
  backwards, so the active match rendered less prominently than the rest
- two hardcoded rgba() values now use --vscode-widget-shadow and
  --vscode-toolbar-hoverBackground; the latter was invisible in dark themes
- dropped -moz-/-ms-user-select prefixes, webviews are Chromium

Also:
- add .vscode/launch.json and tasks.json; F5 debugging was not set up
- ship @vscode/codicons via copy-webpack-plugin into media/codicons/,
  since .vscodeignore excludes node_modules
- localResourceRoots: node_modules (never used) -> media
- getNonce uses crypto.randomBytes instead of Math.random
- add ui/dom.ts and ui/icons.ts for the phase 2 split

style-src keeps 'unsafe-inline' for now: CSP blocks style="..." attributes
in parsed markup and 13 of them drive mode visibility. They go away in
phase 2 when mode switching becomes attribute-driven.

Co-Authored-By: Claude Opus 5 <[email protected]>
Phase 2 of the UI revamp. Structural only -- the UI still looks the same.

controller.ts was a 1592-line god object owning DOM wiring, mode switching,
splitter drag, maximize, search, diff apply/reject, clipboard and folding.
Replaced with:

  shell.ts              toolbar, mode, shortcuts, host messages
  views/format-view.ts  input/output panes, format, folding, copy, save
  views/diff-view.ts    compare, per-row and bulk apply/reject/undo
  ui/messaging.ts       typed transport + ready handshake
  ui/shortcuts.ts       the single keydown registry
  ui/splitter.ts        drag-to-resize between two panes
  ui/panels.ts          maximize/restore via delegation
  ui/search-bar.ts      the toolbar search bar
  shared/messages.ts    message contract, imported by both bundles

Defects fixed along the way:

- Two independent document keydown listeners both claimed Cmd+0 and relied
  on mode checks to avoid colliding. One registry now owns every binding and
  dispatches exactly one match.
- Maximize re-bound its buttons on every mode switch and cloned each node to
  shed the old listener, silently discarding listeners attached to the
  button's children. Now a single delegated listener on the container.
- Loading history into a panel that did not exist yet posted the message
  after a fixed 100ms, which dropped it on a slow load. The webview now
  signals ready and the host queues and flushes.
- reject-all only added a CSS class and never recorded the state, so a later
  undo on a row behaved as if it had never been rejected.
- switchMode mutated style.display on six elements across ~75 lines. Mode is
  now one data-mode attribute on <body> and CSS decides what each mode shows.

With no style attributes left in generated markup, style-src drops
'unsafe-inline' and is now just ${webview.cspSource}.

Copy is no longer hidden in diff mode; the diff branch of the copy handler
already existed but was unreachable.

Testing: jest now runs two projects, node for the engines and jsdom for
anything touching the DOM. 40 new tests cover the shortcut registry, the
maximize group, diff resolution state and shell wiring -- 174 -> 214.
The shell suite covers the initial-mode regression this refactor introduced
and I caught during verification.

Co-Authored-By: Claude Opus 5 <[email protected]>
Phase 3 of the UI revamp. First phase with a visible change.

The panel read as a web app hosted in VS Code: a 48px toolbar of text
buttons, 8px card radii, 16px page padding, floating action buttons
overlaying pane content, and -apple-system type. This rebuilds the chrome
to match the editor it lives in.

Design tokens
- Every colour, font and metric now resolves through media/tokens.css.
  Nothing else references a --vscode-* variable, so retheming happens in
  one place and no rule can quietly hardcode a colour. Verified: zero
  literal colours anywhere in media/ outside the token file.
- High-contrast themes override the tokens on body.vscode-high-contrast,
  which reaches every rule without any of them knowing about the theme.

Chrome
- Toolbar 36px, pane headers 28px, status bar 22px, matching VS Code's
  own chrome heights.
- Mode switcher restyled after the panel tabs (Problems/Output/Terminal):
  flat labels with an underline on the active one.
- Pane actions moved into per-pane header bars. This retires the absolutely
  positioned overlay buttons and the `right: 88px`/`right: 48px` nth-of-type
  offsets that had to be renumbered whenever a button was added or hidden.
- New status bar: validity, line count and size in Format; counts by change
  kind in Diff. Each view keeps its own model, so switching modes restores
  it rather than recomputing.
- Empty state in the output pane with a keyboard legend. The modifier key
  is resolved at runtime, so macOS sees the Command symbol rather than Ctrl.

Icons
- @vscode/codicons replaces every hand-drawn SVG. The maximize path had
  been duplicated five times in markup plus twice as JS strings, and the
  check/close/undo trio three times in diff.ts. Zero inline <svg> remain.
- The panel tab icon is now a light/dark pair. iconPath renders outside the
  webview so it cannot pick up theme colours through CSS, which is why
  currentColor would not have worked. Also replaced the <text>{}</text>
  hack with real paths, since it depended on a monospace font being present.

Two rendering bugs found while reviewing the result:
- Modified diff rows reused --vscode-diffEditor-border, a line colour, as
  a background fill. Subtle in dark themes, but a grey band that read as a
  selection in light ones. They now carry meaning in the rail and value
  chips alone.
- .diff-item-header used space-between across four children, so path,
  separator, value and actions spread apart and neighbouring rows' values
  landed at different offsets. Actions now push right on their own.

The gutter had 32px of accumulated padding across three rules; now 16px.

Testing: DOM fixtures are now generated from the real
WebviewContentGenerator via a stubbed vscode module, so tests assert
against production markup instead of a hand-copied approximation that
could drift. 223 tests pass.

Co-Authored-By: Claude Opus 5 <[email protected]>
Phase 4 of the UI revamp.

Search lived in the toolbar, where opening it made the trigger button
disappear and swap places with the input. It now floats over the content
it searches, like the editor's own find control.

The widget carries a term field, match-case and regex toggles, a match
counter, previous/next/close, and a scope row: All, Keys, Values. The term
and every option survive close and reopen.

Behaviour fixes:
- Opening find used to return early when nothing had been formatted, so on
  a fresh panel with JSON already pasted the button appeared dead. It now
  formats first and then searches.
- The gutter was searchable, so looking for "1" lit up line numbers
  alongside real hits. Line numbers and folding markers are now excluded
  from every scope.
- Re-rendering the output (toggling line numbers, reformatting) discarded
  the highlights and left a stale match count. The widget re-runs itself.
- An invalid regular expression reports "Invalid pattern" rather than
  silently reporting no matches.

search() takes an options object; every option defaults to the previous
behaviour, so nothing else had to change. Scope works by filtering the tree
walker to text nodes inside key or value token spans, which means the
haystack is the searchable text and offsets still map straight back onto
the nodes that produced them.

The pattern is no longer lowercased for case-insensitive search -- that
would have turned \S into \s once regex support existed. Casing is handled
where the match happens instead.

Folding was quadratic: each hidden element searched the whole line list for
its own index in order to find its gutter entry. The formatter now emits
data-line on both, making it a direct lookup.

Testing: 20 new find-widget tests covering scope, case, regex, invalid
patterns, gutter exclusion and re-render survival. jsdom implements no
layout and therefore no scrollIntoView, so that is stubbed in setup rather
than making the code defensive about an API browsers always have.
174 -> 243 tests over the four phases.

Co-Authored-By: Claude Opus 5 <[email protected]>
Phase 5 of the UI revamp.

Layout
- The three panes are resizable. Previously only Format had a splitter;
  Diff's panes were fixed at a third each, which made a deep path or a long
  value unreadable with no way to give the list more room.
- Splitter now sizes relative to its own two neighbours rather than the
  containing row. That is what lets two of them coexist: dragging one
  redistributes only the width those two panes already share and leaves
  every other pane where it is. Verified in the browser -- moving the left
  sash 80px shifted 80px from pane one to pane two and left pane three
  untouched.

Change rows
- Path renders as breadcrumb segments with the leaf emphasised, and array
  indices show as [0] rather than reading like another key. A dotted path
  was unreadable once nesting got deep.
- Value moved onto its own line under the path. On one line a long value
  wrapped into the path and neighbouring rows could not be scanned.
- Modified rows strike through the old value and point at the new one; add
  and remove show only the value they carry. The bare "= value" the old
  markup produced read as an assignment rather than a change.
- Each row carries a type glyph tinted to match its rail.

Filtering
- Chips above the list: All, Added, Removed, Modified, each with a live
  count. A chip with nothing to show dims and stops responding.
- Filtering sets one attribute on the list and every row decides for itself
  in CSS, so no DOM walking and nothing to keep in sync.

Resolution state
- Applied and rejected are now a single data-state attribute rather than
  parallel CSS classes, so what is recorded and what is on screen cannot
  drift. Resolved rows keep their actions visible so undo is discoverable,
  and carry a status dot -- dimming alone is hard to read in some themes.

Testing: diff-view tests now build from the real panel markup like the
other DOM suites, rather than a hand-copied fixture that had already
drifted. 23 new tests across change-row rendering, filters and the
splitter's pair-relative sizing. 243 -> 266.

Co-Authored-By: Claude Opus 5 <[email protected]>
@LucianCrainic
LucianCrainic merged commit 493f7de into develop Aug 14, 2026
@LucianCrainic
LucianCrainic deleted the feat/ui-revamp branch August 15, 2026 11:01
LucianCrainic added a commit that referenced this pull request Aug 15, 2026
feat(ui): rebuild the panel UI on a design-token system
LucianCrainic added a commit that referenced this pull request Aug 15, 2026
The work PR #7 shipped without.

Panels are serialised, so a window reload no longer throws away whatever
was pasted: `registerWebviewPanelSerializer` adopts the panel VS Code
offers back, and the webview keeps mode, input and toggles in setState.
Writes are coalesced and anything over 512 KB is dropped rather than
carried, since the whole state is re-serialised on each write and
reformatting is cheaper than stalling every keystroke.

Sidebar history moves to globalState. It was a plain array on the tree
provider, so every entry a user saved vanished on restart -- which made
the feature close to pointless. Entries now carry a timestamp and a size
and are described as "3 minutes ago - 12.4 KB" instead of "Entry 1" plus
a raw fifty-character slice, which all look alike when they start with
`{"`. Documents over 256 KB are stored as a preview and say so, rather
than keeping fifty large documents in global state forever.

`getChildren` dispatched on the item's *label* matching the string
'Format History', so renaming a heading would have silently emptied the
tree under it; items carry a typed kind now. Added a "Clear history"
title action.

contributes.configuration adds nine settings -- line numbers, indent
size, strict diff, pane ratio, format on paste, default search scope,
and the three limits the engines now respect. They are pushed to open
panels on the ready handshake and again whenever they change. The diff
view reports the document-size limit plainly instead of attempting a
comparison that will not fit.

`jsonbro.loadFormatHistory` and `jsonbro.loadDiffHistory` were
registered in code but absent from contributes; they are declared now,
and hidden from the palette since they take arguments.

Also: .vscodeignore was packaging the preview harness output and
.claude/launch.json into the .vsix -- vsce includes untracked files
unless they are named there. Verified with `vsce ls`: 60 files, media
and out only.

README.md untouched, as asked.

400 tests pass, up from 375.
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