Skip to content

Show context snippets for content searches#213

Draft
franciscoxc wants to merge 1 commit into
cardisoft:masterfrom
franciscoxc:content-search-context-column
Draft

Show context snippets for content searches#213
franciscoxc wants to merge 1 commit 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 on lines +8 to +13
const char = query[index];
if (char === '\\' && index + 1 < query.length) {
value += query[index + 1];
index += 2;
continue;
}
Comment on lines +42 to +47
while (index < query.length) {
const matchIndex = lowerQuery.indexOf(CONTENT_PREFIX, index);
if (matchIndex === -1) {
break;
}

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();
}
}
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