feat(app): persist search history with a clickable recent-searches dropdown#222
Open
zengtianli wants to merge 1 commit into
Open
feat(app): persist search history with a clickable recent-searches dropdown#222zengtianli wants to merge 1 commit into
zengtianli wants to merge 1 commit into
Conversation
…opdown Complements the in-memory ArrowUp/ArrowDown history from cardisoft#31 (useSearchHistory.ts) by persisting queries across app restarts and surfacing them in a clickable panel. - New useRecentSearches hook wraps useStoredState to persist a newest-first, deduped, capped-at-50 list under localStorage key cardinal.recentSearches. - History records on query submit AND on opening a result (double-click / Cmd+O / context menu) via a small subscribeResultOpened pub/sub in openResultPath. - SearchBar gains a clock-icon toggle + dropdown (re-run a query, clear history, Esc / outside-click to close); native button semantics, aria-haspopup on toggle. - Fully i18n'd across all 15 locales; light/dark via existing CSS variables. - 6 unit tests for ordering, trimming, dedup, cap, restore/clear, malformed payload.
zengtianli
added a commit
to zengtianli/cardinal
that referenced
this pull request
Jul 19, 2026
ldm0
self-requested a review
July 19, 2026 13:54
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Intro
This PR adds a persistent search history to the file-search bar: past queries are saved across app restarts and can be re-run with a single click from a small clock-icon dropdown next to the search options.
It builds directly on top of the in-memory ArrowUp/ArrowDown history from #31 rather than replacing it — see How it relates to #31 below.
What & why
The ArrowUp/ArrowDown history added in #31 is great for cycling through queries within a session, but it lives entirely in memory and disappears on restart, and it's only reachable via the keyboard. This PR complements it with:
localStorageundercardinal.recentSearches, newest-first, deduped, capped at 50 entries).Escor an outside click.Cmd+O, or the context menu), on the reasoning that a search which led to an open is a search worth remembering.Implementation
Key files:
src/hooks/useRecentSearches.tsuseStoredStateto persist a newest-first, deduped, capped list; exposesrecordSearch/clearRecentSearches. Trims blanks and ignores malformed persisted payloads.src/utils/openResultPath.tssubscribeResultOpenedpub/sub so any result-open path (double-click /Cmd+O/ context menu) can notify subscribers without prop-drilling.src/hooks/useFilesTabState.tsonQueryCommittedcallback, fired when a query is submitted, so committed queries flow into history.src/components/SearchBar.tsxEsc/ outside-click handling and ARIA (aria-haspopup/aria-expandedon the toggle, labelled panel, native<button>semantics for entries). All strings are props.src/App.tsxsubscribeResultOpened, and passes i18n'd labels.src/App.csssrc/i18n/resources/*.jsonsearch.history.{toggle,empty,clear}keys across all 15 locales.src/hooks/__tests__/useRecentSearches.test.tsNotes:
useStoredStatehelper rather than hand-rolling storage access.historyEnabled) so it doesn't appear where it wouldn't make sense.--color-accent,--color-elevated-bg, etc.), so light/dark both work with no extra tokens.How it relates to #31
This is complementary, not a replacement:
useSearchHistory.ts) gives in-memory ArrowUp/ArrowDown cycling within a session — fast keyboard recall while you work.localStorageacross sessions and surfaces them in a clickable dropdown — durable recall and mouse discoverability.The two coexist: the keyboard history from #31 is untouched (a separate hook file), and this PR layers persistence + a visible UI on top.
Testing
Ran from
cardinal/:npm run format:check— clean.npm run typecheck(tsc --noEmit) — clean, no type errors.npm test -- --run(vitest) — all green (278 passed), including 6 new unit tests foruseRecentSearchescovering: newest-first ordering + persistence, blank/whitespace trimming, dedup-to-front, cap at max entries, restore-on-mount + clear, and rejecting malformed persisted payloads.npm run build(vite) — succeeds.No Rust was touched.
Screenshots
A screenshot / GIF of the dropdown in action can be added here on request.