Skip to content

feat: add persistent switches to PopupBuilder#122

Merged
actionshrimp merged 2 commits intomainfrom
feature/popup-persistent-switches
Mar 12, 2026
Merged

feat: add persistent switches to PopupBuilder#122
actionshrimp merged 2 commits intomainfrom
feature/popup-persistent-switches

Conversation

@actionshrimp
Copy link
Owner

Summary

  • Adds magit-style sticky popup switches that persist their enabled state across popup invocations via persist_key opt on PopupBuilder:switch()
  • New lua/gitlad/utils/persist.lua — lightweight JSON key-value store (stdpath("data")/gitlad/popup_switches.json)
  • PopupData:build() loads persisted state (overrides opts.enabled); toggle_switch() saves on every toggle, including force-disabled exclusive switches
  • New GitladPopupSwitchPersistent highlight group (DiagnosticHint) visually distinguishes persistent-on from transient-on switches in the popup UI

This is PR 1 of the worktrunk integration plan (WORKTRUNK_PLAN.md). The persistent switch infrastructure will be used by the --copy-ignored flag in PR 2.

Test plan

  • make test passes (1610 unit + 647 e2e, all green)
  • make lint passes
  • Open any popup, toggle a switch with persist_key, close and reopen — switch should still be enabled
  • Non-persistent switches reset to default on each popup open
  • Persistent-on switches render with a visually distinct highlight (hint/blue vs ok/green)

Introduces magit-style sticky popup switches that remember their enabled
state across popup invocations. A switch with a `persist_key` saves its
state to stdpath("data")/gitlad/popup_switches.json on every toggle and
loads it back when the popup is built.

- New `lua/gitlad/utils/persist.lua` — lightweight JSON key-value store
  with `_override_path` for test isolation
- `PopupBuilder:switch()` gains `persist_key?` opt
- `PopupData:build()` loads persisted state, overriding `opts.enabled`
- `PopupData:toggle_switch()` saves state; also persists exclusive
  switches that get force-disabled by mutual exclusion
- New `GitladPopupSwitchPersistent` highlight group (DiagnosticHint)
  visually distinguishes persistent-on from transient-on switches
- 14 unit tests + 4 e2e tests

Will be used by the worktrunk `--copy-ignored` switch in PR 2.
@actionshrimp
Copy link
Owner Author

Re: testing this PR — there's nothing to observe with make dev yet. No existing popup has persist_key on any of its switches; that wiring happens in PR 2 (the worktrunk popup). The cross-session persistence mechanism is verified by the e2e test I just added (test_popup_persist.lua → "cross-session: persistent switch survives Neovim restart"), which writes state in one child Neovim process and reads it back in a fresh one. The feature is correct, just not surfaced on any real popup until PR 2.

@actionshrimp actionshrimp merged commit 32c3e69 into main Mar 12, 2026
3 checks passed
@actionshrimp actionshrimp deleted the feature/popup-persistent-switches branch March 12, 2026 19:46
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