Skip to content

Enhancement/search navigation#11

Merged
bizzkoot merged 8 commits intodevfrom
enhancement/search-navigation
Jan 16, 2026
Merged

Enhancement/search navigation#11
bizzkoot merged 8 commits intodevfrom
enhancement/search-navigation

Conversation

@bizzkoot
Copy link
Owner

PR: Chat Search Navigation & Highlights

Overview

This PR adds chat search functionality with keyboard navigation, match highlighting, and auto-expansion of collapsed sections.

What's Implemented

  • Search Panel (packages/ui/src/components/search-panel.tsx): Floating UI with query input, navigation buttons, match counter, and options (case-sensitive, whole-word, tool outputs, reasoning blocks)
  • Search Store (packages/ui/src/stores/search-store.ts): Centralized state for query, matches, currentIndex, navigation (navigateNext/navigatePrevious), and scroll-to-match logic
  • Match Highlighting:
    • Plain-text messages: Reactive rendering via SearchHighlightedText component with reliable search-match--current outline
    • Markdown (assistant messages): DOM-based highlight wrapping via TreeWalker
  • Auto-Expansion (packages/ui/src/lib/section-expansion.ts): Expands reasoning blocks, tool calls, folder nodes, sidebar accordions on navigation
  • Keyboard Shortcuts: Cmd+F/Ctrl+F to open, Esc to close, Enter/Shift+Enter to navigate, arrow keys for navigation
  • Debounced Auto-Search: 400ms debounce on query input for better UX
  • Closest-to-Viewport Initial Selection: When search executes, currentIndex defaults to match nearest visible viewport

Commits (7 ahead of origin/dev)

  1. f3bba7e — feat(ui): add chat search panel + highlights
  2. 82f732d — fix(ui): resolve search highlight bug in Markdown component using direct index matching
  3. f3c7fc3 — feat(search): auto-expand collapsed sections when navigating to search results
  4. a1696c8 — fix(search): remove console warnings for missing match elements
  5. d3db2eb — fix(search): use message anchors to find closest match
  6. 78ef347 — feat(search): add debounced auto-search for better UX
  7. 0b528a7 — fix(search): improve highlight reliability with DOM retry logic

Known Limitation

Current match outline (search-match--current) may not appear in assistant panel

Symptoms

  • All matches highlight correctly (yellow background)
  • No outline appears on the "current" match when navigating via search panel
  • Issue observed in:
    • A) Normal assistant markdown text (rendered by Markdown component)
    • B) Tool output / reasoning block content (collapsed sections requiring expansion)

Root Cause

Markdown component uses DOM-based post-render highlighting:

  1. Wraps all occurrences in <mark class="search-match"> via TreeWalker → always works
  2. Locates "current" match via selector matching data-search-start/end or data-search-occurrencecan fail due to timing/race conditions

Navigation flow:

  • navigateNext() / navigatePrevious() updates currentIndex in store
  • scrollToCurrentMatch() expands sections and scrolls (may fall back to message anchor if marks not yet found)
  • Markdown.applySearchHighlights() tries to add search-match--current to the specific mark via selector
  • If selector fails (element not in DOM yet, offsets mismatch), no outline is applied → no visual "current" indicator

Latest commit (0b528a7) added retry logic to mitigate but does not fully eliminate the issue for:

  • Collapsed reasoning/tool blocks (B): expansion is async; marks may not exist when selector runs
  • Markdown re-render timing (A): globalIndexOffset computation can drift from store's startIndex/endIndex

Why Accept as MVP

  • Complexity to fix: Requires unifying highlight rendering (reactive vs DOM mutation) or reliable index mapping across markdown pipeline
  • Value: Users still see all highlighted matches; navigation works via scroll; "current" outline is a nice-to-have visual affordance
  • Tradeoff: Fix would add significant DOM/event plumbing; MVP provides core search utility today

Plain-text user messages continue to work reliably (SearchHighlightedText computes isCurrent reactively and sets class during render).


Testing Notes

  • Manual testing done during implementation; no automated tests added yet
  • Verify: npm run typecheck passes before merge
  • Verify: Search opens/closes, keyboard shortcuts work, matches highlight and scroll
  • Known issue: Check assistant panel (markdown, reasoning, tool output) for missing outline after navigation

…h results

- Add section-expansion.ts module with event system for triggering expansion
- Expand reasoning blocks, tool outputs, sidebar accordions, folder nodes on navigation
- Add event listeners to ReasoningCard, ToolCall, InstanceShell2, FolderTreeNode
- Integrate expansion logic into scrollToCurrentMatch() in search-store.ts
- Wait for DOM updates after expansion before scrolling

Components now respond to search navigation by auto-expanding
collapsed sections containing search matches.

Closes: Search expansion implementation
- Remove console.warn() calls that were showing 'Match element not found'
- These warnings are expected when elements haven't rendered yet
- Expansion still works via metadata-based triggers

Silent search navigation
- Replace DOM element lookups with message anchor positions
- Finds anchor closest to viewport center
- Then finds first match in that message
- Works even before DOM highlighting is applied

This should fix the issue where search always went to top
- Add 400ms debounce timer to auto-search after typing stops
- Clear old search results immediately when query changes
- This fixes the issue where old highlights remained when user selects-all and types new text
- Use reactive state management (clearing matches) instead of DOM manipulation
- Add timer cleanup in closeSearch and executeSearchOnEnter to prevent memory leaks
- Update search panel to pass store parameter to setQueryInput

Replaces the previous approach of manually clearing DOM highlights which
didn't work due to SolidJS reactive re-rendering.
@bizzkoot bizzkoot merged commit 5353ed0 into dev Jan 16, 2026
@bizzkoot bizzkoot deleted the enhancement/search-navigation branch January 16, 2026 14:38
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

Comments