Skip to content

Show context snippets for content searches - #213

Draft
franciscoxc wants to merge 10 commits into
cardisoft:masterfrom
franciscoxc:content-search-context-column
Draft

Show context snippets for content searches#213
franciscoxc wants to merge 10 commits into
cardisoft:masterfrom
franciscoxc:content-search-context-column

Conversation

@franciscoxc

@franciscoxc franciscoxc commented May 31, 2026

Copy link
Copy Markdown

Hi! I noticed this issue is already assigned, so please treat this PR as a proposed implementation / proof of concept rather than an assumption about the final direction.

I tested this locally and wanted to share it in case it helps, or in case parts of it match what you had in mind for content search results.

What this changes

  • Detects content: terms in the current query on the frontend.
  • Shows a Context column only when a content: query is active.
  • Places the context column first so the matched text is visible without horizontal scrolling.
  • Fetches a small snippet around the first matching content term for visible rows.
  • Highlights the searched content term inside the snippet.

Notes

  • The snippet favors a little text before the match and more text after it, so the match is usually visible near the beginning of the cell.
  • Context snippets are loaded through get_nodes_info, so they are fetched with row metadata rather than changing the search result contract.
  • For non-content: searches, the table layout remains unchanged.

Implementation map

  • contentQuery.ts: extracts content: terms from the current search query.
  • useDataLoader.ts: passes content terms to get_nodes_info.
  • commands.rs: reads a small snippet around the first content match.
  • ColumnHeader.tsx / FileRow.tsx: render the conditional Context column.
  • MiddleEllipsisHighlight.tsx: supports end ellipsis for snippets.

Testing

  • npm test -- --run src/components/MiddleEllipsisHighlight.test.ts src/utils/__tests__/contentQuery.test.ts src/hooks/__tests__/useDataLoader.test.ts
  • npm run typecheck
  • cargo fmt -- --check
  • cargo check --all-targets

Related to #212.

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Pull request overview

This PR proposes an MVP/proof-of-concept for displaying per-result context snippets when a search query uses the content: filter, by conditionally adding a Context column and lazily hydrating snippets for visible rows via get_nodes_info.

Changes:

  • Adds frontend parsing for content: terms and threads them through the virtualized results pipeline to request snippet context.
  • Adds a conditional Context column in the files results table (rendered only when content: is present) and supports end-ellipsis highlighting for snippets.
  • Extends the Tauri get_nodes_info command to optionally read and return a short content snippet around the first match.

Reviewed changes

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

Show a summary per file
File Description
cardinal/src/utils/contentQuery.ts New helper to extract content: terms from the user query.
cardinal/src/utils/tests/contentQuery.test.ts Unit tests for extractContentTerms.
cardinal/src/types/search.ts Adds contentContext to node/result typings.
cardinal/src/i18n/resources/ar-SA.json Adds columns.context translation key.
cardinal/src/i18n/resources/de-DE.json Adds columns.context translation key.
cardinal/src/i18n/resources/en-US.json Adds columns.context translation key.
cardinal/src/i18n/resources/es-ES.json Adds columns.context translation key.
cardinal/src/i18n/resources/fr-FR.json Adds columns.context translation key.
cardinal/src/i18n/resources/hi-IN.json Adds columns.context translation key.
cardinal/src/i18n/resources/it-IT.json Adds columns.context translation key.
cardinal/src/i18n/resources/ja-JP.json Adds columns.context translation key.
cardinal/src/i18n/resources/ko-KR.json Adds columns.context translation key.
cardinal/src/i18n/resources/pt-BR.json Adds columns.context translation key.
cardinal/src/i18n/resources/ru-RU.json Adds columns.context translation key.
cardinal/src/i18n/resources/tr-TR.json Adds columns.context translation key.
cardinal/src/i18n/resources/uk-UA.json Adds columns.context translation key.
cardinal/src/i18n/resources/zh-CN.json Adds columns.context translation key.
cardinal/src/i18n/resources/zh-TW.json Adds columns.context translation key.
cardinal/src/hooks/useDataLoader.ts Threads content-term options through get_nodes_info hydration.
cardinal/src/hooks/tests/useDataLoader.test.ts Verifies content snippet options are passed to get_nodes_info.
cardinal/src/components/VirtualList.tsx Passes content-term options into useDataLoader.
cardinal/src/components/MiddleEllipsisHighlight.tsx Adds an ellipsisMode="end" option for snippet-friendly truncation.
cardinal/src/components/FilesTabContent.tsx Toggles a context-aware layout class and passes snippet options to VirtualList.
cardinal/src/components/FileRow.tsx Renders the Context cell and highlights content terms within the snippet.
cardinal/src/components/ColumnHeader.tsx Conditionally renders the Context column header label.
cardinal/src/App.tsx Detects content: terms, toggles Context column layout, and passes snippet options down.
cardinal/src/App.css Adds grid/CSS variable support for a context-first column layout.
cardinal/src-tauri/src/commands.rs Extends get_nodes_info to optionally read and return a context snippet.

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

Comment thread cardinal/src/utils/contentQuery.ts Outdated
Comment on lines +8 to +13
const char = query[index];
if (char === '\\' && index + 1 < query.length) {
value += query[index + 1];
index += 2;
continue;
}
Comment thread cardinal/src/utils/contentQuery.ts Outdated
Comment on lines +42 to +47
while (index < query.length) {
const matchIndex = lowerQuery.indexOf(CONTENT_PREFIX, index);
if (matchIndex === -1) {
break;
}

Comment thread cardinal/src-tauri/src/commands.rs Outdated
Comment on lines +471 to +479
let desired_after = match_index + needle.len() + CONTENT_CONTEXT_AFTER_BYTES;
let mut has_suffix = after_end < chunk_len;
if desired_after > chunk_len {
let mut extra = vec![0u8; desired_after - chunk_len];
if let Ok(extra_read) = file.read(&mut extra) {
snippet.extend_from_slice(&extra[..extra_read]);
has_suffix = extra_read == extra.len();
}
}
franciscoxc and others added 9 commits August 1, 2026 13:02
Node 22+ defines its own global `localStorage` accessor that returns
undefined unless `--localstorage-file` is passed. Vitest's populateGlobal
skips copying a jsdom key when one already exists on globalThis unless it
is in an internal allowlist, and `localStorage`/`sessionStorage` are not on
it (`navigator` is). So jsdom's storage never reached window and every test
touching it failed on 51 assertions, while CI on Node 20 stayed green.

Dropping Node's own web storage lets vitest install jsdom's, which the
Storage.prototype spies in i18n/config.test.ts depend on. CI moves to Node
24 because Node 20 rejects the flag outright.

Diagnosis by a prior session; re-applied after its worktree was pruned.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
Three changes that share the search bar and the query pipeline:

- File-type dropdown next to the search bar. Picking a type writes it into
  the query (`type:image`) and the control reads its state back from the
  text, so the two can never disagree and the syntax stays visible instead
  of hidden behind a menu. A query it cannot represent faithfully — negated,
  duplicated, or inside a boolean group — reads as "custom" and is left
  untouched. Native <select>, so keyboard, focus and RTL come from the
  platform.
- `type:email` category: .eml, .emlx, .emlxpart, .msg, .mbox, with
  mail/message as synonyms. Apple Mail's formats are the ones nobody finds
  by name.
- "Folder scope" becomes plain "Search in" across all 15 locales.

Content snippets now come from the engine rather than a second
implementation in the app: `content_snippet` sits next to the matcher it
mirrors in search-cache and shares its chunked read and Rabin-Karp finder,
and the highlighted terms are derived by the real query parser. Two
behaviour fixes fall out: `!content:` no longer highlights anything, and
`content:"Bearer "` keeps its trailing space. Row hydration runs in
parallel, since each row may read a file for its icon and its snippet.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
The search input had no accessible name, making it invisible to
assistive technologies. Added aria-label with i18n key
'search.aria.searchInput' ('Search input') threaded through
App → SearchBar. Updated all 15 locale files.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
(cherry picked from commit 4c50734)
Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
An ad-hoc signature ('-') is what makes macOS show the unidentified-developer
warning on a downloaded build. Signing with the Developer ID, plus
notarization at build time (APPLE_ID / APPLE_TEAM_ID / APPLE_PASSWORD in the
environment), lets Gatekeeper open it without warnings.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
The identifier moves from com.cardinal.one to com.franxc.cardinal. A bundle
identifier is the app's identity to macOS — preferences, LaunchServices and
the Full Disk Access grant all key off it — so a fork signed by a different
team must not reuse upstream's, or the two builds collide on the same Mac.

Icon gets a sparkle cluster by the bird's head, drawn as polygons rather
than the emoji glyph: Apple Color Emoji renders at fixed sizes only and
turns to mush when 1024px is downscaled to the 16px menu-bar icon.

Version goes to 0.2.0 rather than 0.1.24: this is the fork's first release
and it carries user-facing features, so it should not read as the next
upstream patch.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
AGENTS.md named nightly-2025-05-09 while rust-toolchain.toml pins
nightly-2025-12-11. Following the doc and forcing the old toolchain onto
PATH builds fine from a warm target dir and then fails the moment a
proc-macro has to be rebuilt: rustc 1.88 emits dylibs that recent macOS
dyld rejects with 'mis-aligned LINKEDIT string pool'.

The iCloud note is the same lesson as the DoubleMouse release script, one
step earlier: there it stamped com.apple.FinderInfo and broke codesign,
here an evicted fingerprint file hangs cargo in read() with no timeout.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
Four spots where the obvious form is wrong and a later reader would 'clean
them up' straight back into the bug. Each records the symptom, not just the
rule: a trimmed content term stops matching what the engine matched; a
[value] selector never updates on a controlled select; folding the chunk in
place lowercases the snippet; TYPE_TOKEN alone reads a parenthesised
type: filter as 'All types'.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
The fork publishes a signed and notarized DMG, so the first thing the
README should offer is the binary, not the source. The old section pointed
at upstream's releases and at a homebrew cask this fork does not publish.

The link carries the version, so it needs updating on every release --
along with the matching buttons on the franxc.com card and subpage.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
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.

3 participants