Skip to content

feat(viewer): preserve last successful result on null/error#121

Open
laurigates wants to merge 2 commits into
ynqa:mainfrom
laurigates:feat/preserve-view
Open

feat(viewer): preserve last successful result on null/error#121
laurigates wants to merge 2 commits into
ynqa:mainfrom
laurigates:feat/preserve-view

Conversation

@laurigates

Copy link
Copy Markdown

Summary

When a query returns only null or fails (parse/run error), the viewer now keeps showing the most recent successful result instead of resetting the pane to the whole input document. This keeps the view stable so you retain context while fixing the filter (#103).

Before any query has succeeded, it still falls back to the original input. The guide pane keeps reporting the null/error exactly as before.

Behavior

Step Before After
.foo (valid) shows .foo shows .foo (remembered as last-good)
.foo.bad (null) resets to whole document keeps showing .foo
.foo | (error) resets to whole document keeps showing .foo
fix → .foo.bar shows .foo.bar shows .foo.bar (new last-good)

Implementation

  • JsonViewer gains a last_good: Vec<Value> holding the most recent non-null successful result (empty until the first success).
  • Success (non-null) updates last_good and renders it; null/error render last_good, or the original input if nothing has succeeded yet (show_last_good).
  • An empty result is treated like null (the existing all(null) check is vacuously true for empty), so a filter that produces nothing also preserves the view.

The issue lists a few methodologies; this implements "result of the most recent successful query", which best matches keeping context. Easy to switch to always-original-input if you'd prefer.

Closes #103

laurigates and others added 2 commits June 24, 2026 10:30
When a query returns only null or fails to parse/run, the viewer now keeps
showing the most recent successful result instead of resetting to the whole
input document — so the pane stays stable and you keep your context while
fixing the filter (ynqa#103). Before any successful query it still falls back to
the original input.

The guide pane keeps reporting the null/error as before.

Closes ynqa#103

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
An empty (or whitespace-only) query is rejected by jaq as an invalid
program, so it fell through to the `show_last_good()` fallback — which
silently re-displayed the stale last result, or on a fresh view dumped
the entire input document with no explanation. Clearing the filter
(e.g. Ctrl+U) therefore looked like the view "wouldn't clear".

Special-case the empty query as "no filter": reset `last_good` and point
the view at the full input fresh, with a neutral `no filter — showing
full input` status hint. Non-empty incomplete filters (`.fo`, `.a |`)
still preserve the last good result to avoid flicker while typing.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
@laurigates

Copy link
Copy Markdown
Author

Pushed a follow-up that handles the empty-filter case for the preserved view.

Previously, clearing the editor to empty was indistinguishable from a half-typed filter: jaq rejects an empty program as invalid, so it fell through to show_last_good() — which either left the stale last result on screen or, on a fresh view, silently re-displayed the entire input document with no explanation. Clearing the filter looked like the view "wouldn't reset."

Now an empty (or whitespace-only) query is treated explicitly as "no filter": last_good is reset and the view points at the full input fresh, with a neutral no filter — showing full input status hint. Non-empty incomplete filters (.fo, .a |) still preserve the last good result to avoid flicker while typing, exactly as before.

@laurigates

Copy link
Copy Markdown
Author

Related PRs (no strict merge order)#120, #121, and #122 are a small series of viewer / status-line improvements that independently edit the same code (refresh_view_with_query in src/json_viewer.rs, and src/guide.rs). They're independent in intent but overlap textually, so whichever merges first, the others will need a quick rebase — no specific order is required.

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.

Feat: Preserve JSON view when jq returns null or fails

1 participant