Skip to content

feat(code): add Cmd+F search within conversations#2041

Merged
adboio merged 4 commits intoPostHog:mainfrom
Imane-Idrissi:feat/cmd-f-conversation-search
May 5, 2026
Merged

feat(code): add Cmd+F search within conversations#2041
adboio merged 4 commits intoPostHog:mainfrom
Imane-Idrissi:feat/cmd-f-conversation-search

Conversation

@Imane-Idrissi
Copy link
Copy Markdown
Contributor

Closes #1982

Problem

Allow users to use Cmd+F to search for text within a conversation.

Changes

  • New ConversationSearchBar.tsx — search bar UI with match count and prev/next
    buttons
  • New extractSearchableText.ts — extracts searchable text from each conversation
    item type
  • Modified ConversationView.tsx — search state, CSS Highlight API logic, Cmd+F
    shortcut handler
  • Modified VirtualizedList.tsx — added scrollToIndex for navigating to matches
  • Modified keyboard-shortcuts.ts — registered Cmd+F shortcut
  • Modified globals.css — highlight styles (yellow for all matches, orange for current)

How did you test this?

Tested manually : searched words and special characters, navigated with Enter/Shift+Enter/Arrow keys, verified Escape to close, and match count accuracy.

Publish to changelog?

no

Closes PostHog#1982

Add in-conversation search using the CSS Highlight API, allowing users
to find text within the chat without relying on the browser's built-in
Cmd+F (which cannot reach virtualized off-screen items).

- Search bar (Cmd+F) with match count, prev/next navigation
- Per-occurrence matching with sequential Enter/Arrow navigation
- Yellow highlight for all matches, orange for the active match
- Retries highlight after scroll to handle virtualized list rendering
- Searches user messages, agent responses, thoughts, errors, console
  logs, status updates, shell commands, and queued messages
- Excludes tool call blocks (each type renders differently, making
  accurate match counting impossible in collapsed vs expanded state)

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@greptile-apps
Copy link
Copy Markdown
Contributor

greptile-apps Bot commented May 5, 2026

Prompt To Fix All With AI
Fix the following 4 code review issues. Work through them one at a time, proposing concise fixes.

---

### Issue 1 of 4
apps/code/src/renderer/features/sessions/components/ConversationView.tsx:326-338
**Cmd+F handler conflicts with CodeMirrorEditor's identical handler**

`CodeMirrorEditor.tsx` (line 67–82) also registers `document.addEventListener("keydown", handleKeyDown, { capture: true })` for the same `Cmd+F` key with only `stopPropagation` (not `stopImmediatePropagation`). `stopPropagation` on a capture-phase listener attached to `document` does NOT prevent other capture-phase listeners on the same node from firing. When a file is open in the editor alongside a conversation, both handlers will run: the conversation search bar opens AND the CodeMirror find panel opens simultaneously. Replacing `e.stopPropagation()` with `e.stopImmediatePropagation()` would fix this.

### Issue 2 of 4
apps/code/src/renderer/features/sessions/components/ConversationView.tsx:222-324
**Highlights disappear when the user manually scrolls the virtualized list**

The CSS Highlight effect (`useEffect`) only re-runs when `searchQuery`, `searchMatches`, or `currentMatchIndex` change. The virtualized list recycles DOM nodes as the user scrolls, so items entering the viewport after the effect last ran have no highlights applied to them. The retry timeouts (50/150/300 ms) only trigger after explicit next/prev navigation — a user who simply scrolls up or down through the conversation will see the highlights vanish on all items outside the originally-rendered window. To fix this, the highlights need to be reapplied on scroll (e.g., listen to the virtualized list's scroll event and call `applyHighlights` there as well).

### Issue 3 of 4
apps/code/src/renderer/styles/globals.css:1122-1130
Hardcoded hex values for highlight colours are not theme-aware. In dark mode `#ffff00` against a dark background is harsh, and `color: inherit` won't compensate for low contrast. Using CSS custom properties from the design system (or at least `prefers-color-scheme`-scoped overrides) ensures the colours stay readable in both light and dark mode.

```suggestion
::highlight(search-match) {
  background-color: oklch(97% 0.2 100 / 0.7); /* yellow, light mode */
  color: black;
}

::highlight(search-match-active) {
  background-color: oklch(75% 0.18 50 / 0.9); /* orange, light mode */
  color: black;
}

@media (prefers-color-scheme: dark) {
  ::highlight(search-match) {
    background-color: oklch(75% 0.18 100 / 0.5);
    color: white;
  }

  ::highlight(search-match-active) {
    background-color: oklch(65% 0.18 50 / 0.8);
    color: white;
  }
}
```

### Issue 4 of 4
apps/code/src/renderer/features/sessions/components/ConversationView.tsx:294-297
The `applyHighlights` inner function returns a `Range | null`, but every call site discards the return value (`applyHighlights()`). The return statement is a superfluous part (simplicity rule 4) — removing it reduces noise without changing behaviour.

```suggestion
            if (occInItem === targetOccInItem) {
              CSS.highlights.set("search-match-active", new Highlight(range));
              return;
            }
```

Reviews (1): Last reviewed commit: "feat(code): add Cmd+F search within conv..." | Re-trigger Greptile

Comment thread apps/code/src/renderer/features/sessions/components/ConversationView.tsx Outdated
Comment thread apps/code/src/renderer/features/sessions/components/ConversationView.tsx Outdated
Comment thread apps/code/src/renderer/styles/globals.css
Comment thread apps/code/src/renderer/features/sessions/components/ConversationView.tsx Outdated
- Use stopImmediatePropagation to prevent conflict with CodeMirror's Cmd+F
- Reapply highlights on scroll so virtualized items stay highlighted
- Add dark mode styles for search highlights
- Remove superfluous return value from applyHighlights
@adboio adboio self-assigned this May 5, 2026
@adboio adboio enabled auto-merge (squash) May 5, 2026 23:29
@adboio adboio merged commit 4b14357 into PostHog:main May 5, 2026
15 checks passed
@Imane-Idrissi Imane-Idrissi deleted the feat/cmd-f-conversation-search branch May 6, 2026 09:36
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.

Support Cmd+F to search within a conversation

2 participants