feat(code): add Cmd+F search within conversations#2041
Merged
adboio merged 4 commits intoPostHog:mainfrom May 5, 2026
Merged
Conversation
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>
Contributor
Prompt To Fix All With AIFix 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 |
- 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
approved these changes
May 5, 2026
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.
Closes #1982
Problem
Allow users to use Cmd+F to search for text within a conversation.
Changes
ConversationSearchBar.tsx— search bar UI with match count and prev/nextbuttons
extractSearchableText.ts— extracts searchable text from each conversationitem type
ConversationView.tsx— search state, CSS Highlight API logic, Cmd+Fshortcut handler
VirtualizedList.tsx— addedscrollToIndexfor navigating to matcheskeyboard-shortcuts.ts— registered Cmd+F shortcutglobals.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