Skip to content

Reset panel state after inactivity timeout#7

Merged
GordonBeeming merged 2 commits into
mainfrom
gb/panel-reset-timeout
Apr 27, 2026
Merged

Reset panel state after inactivity timeout#7
GordonBeeming merged 2 commits into
mainfrom
gb/panel-reset-timeout

Conversation

@GordonBeeming
Copy link
Copy Markdown
Owner

Summary

  • Panel was holding stale state across hide/show. PanelController caches the FloatingPanel and SearchViewModel for the app's lifetime, so the previous query, scroll position, and selected cell survived every dismiss. Within a single train of thought that's "resume where I left off". Come back an hour later and a stale query is friction, not a feature.
  • Fix. New panelResetTimeout preference (default 2 minutes, configurable in Settings → Behaviour). On show, if the panel has been hidden longer than the timeout, SearchViewModel.resetState() clears the query and runs an empty search synchronously — selectedIndex = 0 and scrollProxy.scrollTo already snap the grid back to the first cell, so no view-layer change. Never keeps the old behaviour for anyone who liked it.
  • Hide is now stamped via a hidePanel() helper (was panel?.orderOut(nil) in three places) so lastHiddenAt stays accurate whether dismissal comes from the hotkey, the dismiss closure, or the paste-to-front-app flow.

Test plan

  • swift build passes.
  • Open panel, type a query, select a mid-list cell, dismiss, reopen within 2 min → previous query and selection restored.
  • Wait > 2 min, reopen → query empty, grid scrolled to top, first cell selected.
  • Settings → Behaviour → set "Reset after" to 30 seconds → reset fires sooner.
  • Set to Never → state survives an arbitrarily long gap.
  • Hotkey toggle, menu-bar dismiss, and Paste to Front App all stamp lastHiddenAt (verify by mixing dismissal paths and observing reset on the next show).

Panel was holding the previous search, scroll position, and selection
across hide/show because PanelController caches the FloatingPanel and
SearchViewModel for the app's lifetime. After a long gap that 'resume'
behaviour is friction, not a feature.

On show, if the panel has been hidden longer than the new
panelResetTimeout preference (default 2 minutes), reset the view-model
back to a clean state — empty query, results re-queried from scratch,
first item selected. Configurable in Settings → Behaviour, with a
Never option for anyone who liked the old behaviour.

Co-authored-by: Claude <noreply@anthropic.com>
Co-authored-by: GitButler <gitbutler@gitbutler.com>
@GordonBeeming GordonBeeming marked this pull request as ready for review April 27, 2026 12:02
Copilot AI review requested due to automatic review settings April 27, 2026 12:02
Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Adds an inactivity-based reset so the search panel doesn’t retain stale query/selection state across long gaps, with a new user preference to configure (or disable) the timeout.

Changes:

  • Add PanelResetTimeout preference (default 2 minutes) and expose it in Settings → Behaviour.
  • Add SearchViewModel.resetState() to clear the query and refresh results immediately.
  • Track panel hide time in PanelController and reset state on show when hidden longer than the configured timeout.

Reviewed changes

Copilot reviewed 4 out of 4 changed files in this pull request and generated 3 comments.

File Description
Sources/Vista/SettingsView.swift Adds a Behaviour-tab picker for the new “Reset after” preference.
Sources/Vista/SearchViewModel.swift Introduces resetState() used to clear and re-run an empty query.
Sources/Vista/Preferences.swift Adds PanelResetTimeout enum + persisted panelResetTimeout preference.
Sources/Vista/PanelController.swift Centralizes hiding via hidePanel(), stamps lastHiddenAt, and resets state on show after timeout.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread Sources/Vista/PanelController.swift Outdated
Comment thread Sources/Vista/SettingsView.swift Outdated
Comment thread Sources/Vista/SearchViewModel.swift
- Cover AppKit's hidesOnDeactivate auto-hide path: route every dismissal through a new FloatingPanel.onHide hook so lastHiddenAt is also stamped when the panel hides on focus loss, not just explicit calls.
- Cancel the debounced query inside SearchViewModel.resetState() so we don't run store.search twice (sync + 120 ms debounced replay).
- Reword the 'Reset after' caption to 'between panel opens' — the previous 'across sessions' wording implied state survived an app relaunch, which it doesn't.

Co-authored-by: Claude <noreply@anthropic.com>
Co-authored-by: GitButler <gitbutler@gitbutler.com>
@GordonBeeming GordonBeeming merged commit addacf5 into main Apr 27, 2026
2 checks passed
@GordonBeeming GordonBeeming deleted the gb/panel-reset-timeout branch April 27, 2026 12:21
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.

2 participants