Skip to content

The agent that grows with you

feat(desktop): wire find-in-page in the renderer

David Metcalfe43e86ea50ec5
diff --git a/apps/desktop/src/app/contrib/wiring.tsx b/apps/desktop/src/app/contrib/wiring.tsx
index ffdc79e65b7..6c2eff3528a 100644
--- a/apps/desktop/src/app/contrib/wiring.tsx
+++ b/apps/desktop/src/app/contrib/wiring.tsx
@@ -16,6 +16,7 @@ import { useLocation, useNavigate } from 'react-router-dom'
import { formatRefValue } from '@/components/assistant-ui/directive-text'
import { BootFailureOverlay } from '@/components/boot-failure-overlay'
import { DesktopInstallOverlay } from '@/components/desktop-install-overlay'
+import { FindBar } from '@/components/find-bar'
import { GatewayConnectingOverlay } from '@/components/gateway-connecting-overlay'
import { NotificationStack } from '@/components/notifications'
import { DesktopOnboardingOverlay } from '@/components/onboarding'
@@ -978,6 +979,7 @@ export function ContribWiring({ children }: { children: ReactNode }) {
<SessionSwitcher />
<FileActionDialogs />
<RemoteFolderPicker />
+ <FindBar />
{settingsOpen && (
<Suspense fallback={null}>
diff --git a/apps/desktop/src/app/hooks/use-keybinds.ts b/apps/desktop/src/app/hooks/use-keybinds.ts
index e4c84963d6b..c2c414a8b99 100644
--- a/apps/desktop/src/app/hooks/use-keybinds.ts
+++ b/apps/desktop/src/app/hooks/use-keybinds.ts
@@ -10,6 +10,7 @@ import { comboAllowedInInput, comboFromEvent, isEditableTarget } from '@/lib/key
import { composerFocusKeysAllowed, isComposerFocusSoftCombo, typeToFocusChar } from '@/lib/keybinds/composer-focus-keys'
import { $repoStatus } from '@/store/coding-status'
import { toggleCommandPalette } from '@/store/command-palette'
+import { openFindBar } from '@/store/find-in-page'
import { $capture, $comboIndex, endCapture, setBinding } from '@/store/keybinds'
import {
requestSessionSearchFocus,
@@ -188,6 +189,7 @@ export function useKeybinds(deps: KeybindRuntimeDeps): void {
// the Win/Linux path where ⌘W reaches the renderer directly.
'view.closeTab': () => void closeActiveTab(id => navigate(sessionRoute(id))),
'view.reopenTab': reopenLastClosedTile,
+ 'view.findInPage': openFindBar,
'appearance.toggleMode': () => setMode(resolvedMode === 'dark' ? 'light' : 'dark'),
diff --git a/apps/desktop/src/components/find-bar.tsx b/apps/desktop/src/components/find-bar.tsx
new file mode 100644
index 00000000000..aa46bd3e4e4
--- /dev/null
+++ b/apps/desktop/src/components/find-bar.tsx
@@ -0,0 +1,193 @@
+import { useStore } from '@nanostores/react'
+import { useEffect, useRef, useState } from 'react'
+
+import { Tip } from '@/components/ui/tooltip'
+import { useI18n } from '@/i18n'
+import { cn } from '@/lib/utils'
+import {
+ $findInPage,
+ closeFindBar,
+ findNext,
+ findPrevious,
+ initFindInPageListener,
+ setFindQuery
+} from '@/store/find-in-page'
+
+/**
+ * Find-in-page overlay (Ctrl/Cmd+F).
+ *
+ * Drives Electron's `webContents.findInPage` via the preload bridge so the
+ * user gets the native browser-like incremental search (highlight, Enter to
+ * step, Shift+Enter to step backwards, Escape to close) over the rendered
+ * chat transcript + editor panels. Multi-window routing is handled in the
+ * main process — see apps/desktop/electron/find-in-page.ts.
+ */
+export function FindBar() {
+ const { t } = useI18n()
+ const { active, query, matchOrdinal, matchCount } = useStore($findInPage)
+ const inputRef = useRef<HTMLInputElement>(null)
+ const [localQuery, setLocalQuery] = useState('')
+
+ // Focus input when find bar opens.
+ useEffect(() => {
+ if (active) {
+ setLocalQuery('')
+ // Small delay so the DOM paints the input before we focus.
+ const id = requestAnimationFrame(() => inputRef.current?.focus())
+
+ return () => cancelAnimationFrame(id)
+ }
+
+ return undefined
+ }, [active])
+
+ // Subscribe to found-in-page results from the main process.
+ useEffect(() => {
+ const unsub = initFindInPageListener()
+
+ return unsub
+ }, [])
+
+ // Debounce search — fire findInPage 200ms after the user stops typing.
+ // The ref lets us cancel the pending timeout when the bar closes.
+ const debounceRef = useRef<ReturnType<typeof setTimeout> | null>(null)
+
+ useEffect(() => {
+ if (!active || !localQuery) {
+ return undefined
+ }
+
+ const id = setTimeout(() => setFindQuery(localQuery), 200)
+ debounceRef.current = id
+
+ return () => {
+ clearTimeout(id)
+ debounceRef.current = null
+ }
+ }, [active, localQuery])
+
+ // Cancel pending debounce + close highlights when the bar closes.
+ useEffect(() => {
+ if (!active && debounceRef.current) {
+ clearTimeout(debounceRef.current)
+ debounceRef.current = null
+ }
+ }, [active])
+
+ // Global Escape listener — works even when focus is outside the input.
+ // Captured so the find bar can always close regardless of which element
+ // inside the shell owns focus (composer textarea, side panel button, etc).
+ useEffect(() => {
+ if (!active) {
+ return undefined
+ }
+
+ const onKeyDown = (e: KeyboardEvent) => {
+ if (e.key === 'Escape') {
+ e.preventDefault()
+ closeFindBar()
+ }
+ }
+
+ window.addEventListener('keydown', onKeyDown, { capture: true })
+
+ return () => window.removeEventListener('keydown', onKeyDown, { capture: true })
+ }, [active])
+
+ if (!active) {
+ return null
+ }
+
+ const onInput = (e: React.ChangeEvent<HTMLInputElement>) => {
+ const val = e.target.value
+ setLocalQuery(val)
+
+ // Empty query: clear highlights.
+ if (!val) {
+ setFindQuery('')
+ }
+ }
+
+ const onKeyDown = (e: React.KeyboardEvent) => {
+ if (e.key === 'Escape') {
+ e.preventDefault()
+ closeFindBar()
+ } else if (e.key === 'Enter') {
+ e.preventDefault()
+
+ if (e.shiftKey) {
+ findPrevious()
+ } else {
+ findNext()
+ }
+ }
+ }
+
+ const matchLabel =
+ query && matchCount > 0
+ ? `${matchOrdinal}/${matchCount}`
+ : query && matchCount === 0
+ ? '0/0'
+ : ''
+
+ return (
+ <div
+ className={cn(
+ 'pointer-events-auto fixed right-4 top-[calc(var(--titlebar-height,0px)+0.5rem)] z-50',
+ 'flex items-center gap-1 rounded-lg border border-(--ui-stroke-tertiary) bg-(--ui-surface-background) px-2 py-1 shadow-md'
+ )}
+ >
+ <input
+ className="h-6 w-40 bg-transparent text-xs text-(--ui-text-primary) outline-none placeholder:text-(--ui-text-tertiary)"
+ onChange={onInput}
+ onKeyDown={onKeyDown}
+ placeholder={t.keybinds.actions['view.findInPage'] ?? 'Find'}
+ ref={inputRef}
+ type="text"
+ value={localQuery}
+ />
+
+ {matchLabel && (
+ <span className="min-w-[3rem] text-center text-[0.6875rem] text-(--ui-text-tertiary)">
+ {matchLabel}
+ </span>
+ )}
+
+ <Tip label="Previous">
+ <button
+ className="flex h-5 w-5 items-center justify-center rounded text-(--ui-text-secondary) hover:bg-(--ui-control-hover-background)"
+ onClick={findPrevious}
+ type="button"
+ >
+ <svg height="12" viewBox="0 0 16 16" width="12">
+ <path d="M4 10l4-4 4 4" fill="none" stroke="currentColor" strokeWidth="1.5" />
+ </svg>
+ </button>
+ </Tip>
+
+ <Tip label="Next">
+ <button
+ className="flex h-5 w-5 items-center justify-center rounded text-(--ui-text-secondary) hover:bg-(--ui-control-hover-background)"
+ onClick={findNext}
+ type="button"
+ >
+ <svg height="12" viewBox="0 0 16 16" width="12">
+ <path d="M4 6l4 4 4-4" fill="none" stroke="currentColor" strokeWidth="1.5" />
+ </svg>
+ </button>
+ </Tip>
+
+ <Tip label="Close">
+ <button
+ className="flex h-5 w-5 items-center justify-center rounded text-(--ui-text-secondary) hover:bg-(--ui-control-hover-background)"
+ onClick={closeFindBar}
+ type="button"
+ >
+ <svg height="10" viewBox="0 0 12 12" width="10">
+ <path d="M1 1l10 10M11 1L1 11" stroke="currentColor" strokeWidth="1.5" />
+ </svg>
+ </button>
+ </Tip>
+ </div>
+ )
+}
diff --git a/apps/desktop/src/i18n/en.ts b/apps/desktop/src/i18n/en.ts
index fb5628eb4b3..d083e9883f9 100644
--- a/apps/desktop/src/i18n/en.ts
+++ b/apps/desktop/src/i18n/en.ts
@@ -267,6 +267,7 @@ export const en: Translations = {
'view.closeTab': 'Close tab',
'view.reopenTab': 'Reopen closed tab',
'view.flipPanes': 'Swap sidebar sides',
+ 'view.findInPage': 'Find in page',
'appearance.toggleMode': 'Toggle light / dark',
'profile.default': 'Switch to default profile',
'profile.switch.1': 'Switch to profile 1',
diff --git a/apps/desktop/src/i18n/zh.ts b/apps/desktop/src/i18n/zh.ts
index 687315be7a6..d7e8fbcc180 100644
--- a/apps/desktop/src/i18n/zh.ts
+++ b/apps/desktop/src/i18n/zh.ts
@@ -258,6 +258,7 @@ export const zh: Translations = {
'view.closeTab': '关闭标签',
'view.reopenTab': '重新打开已关闭的标签',
'view.flipPanes': '交换侧边栏位置',
+ 'view.findInPage': '页面内查找',
'appearance.toggleMode': '切换浅色/深色',
'profile.default': '切换到默认配置',
'profile.switch.1': '切换到配置 1',
diff --git a/apps/desktop/src/lib/keybinds/actions.ts b/apps/desktop/src/lib/keybinds/actions.ts
index 122e31fb54c..cd2daa336bd 100644
--- a/apps/desktop/src/lib/keybinds/actions.ts
+++ b/apps/desktop/src/lib/keybinds/actions.ts
@@ -122,6 +122,10 @@ export const KEYBIND_ACTIONS: readonly KeybindActionMeta[] = [
// is a no-op. ⌘⇧T reopens the last closed tab where it was.
{ id: 'view.closeTab', category: 'view', defaults: ['mod+w'] },
{ id: 'view.reopenTab', category: 'view', defaults: ['mod+shift+t'] },
+ // ⌘F — open the find-in-page bar. `comboAllowedInInput` lets the combo
+ // fire from inside a textarea / contenteditable (matches browser behavior
+ // so typing in the composer and pressing ⌘F focuses find, not 'f').
+ { id: 'view.findInPage', category: 'view', defaults: ['mod+f'] },
{ id: 'appearance.toggleMode', category: 'view', defaults: ['shift+x'] },
{ id: 'keybinds.openPanel', category: 'view', defaults: ['mod+/'] }
]
diff --git a/apps/desktop/src/store/find-in-page.ts b/apps/desktop/src/store/find-in-page.ts
new file mode 100644
index 00000000000..23e62712c99
--- /dev/null
+++ b/apps/desktop/src/store/find-in-page.ts
@@ -0,0 +1,66 @@
+import { atom } from 'nanostores'
+
+export interface FindInPageState {
+ active: boolean
+ query: string
+ matchOrdinal: number
+ matchCount: number
+}
+
+export const $findInPage = atom<FindInPageState>({
+ active: false,
+ query: '',
+ matchOrdinal: 0,
+ matchCount: 0
+})
+
+export function openFindBar(): void {
+ $findInPage.set({ active: true, query: '', matchOrdinal: 0, matchCount: 0 })
+}
+
+export function closeFindBar(): void {
+ $findInPage.set({ active: false, query: '', matchOrdinal: 0, matchCount: 0 })
+ void window.hermesDesktop?.stopFindInPage()
+}
+
+export function setFindQuery(query: string): void {
+ const prev = $findInPage.get()
+ $findInPage.set({ ...prev, query })
+
+ if (!query) {
+ void window.hermesDesktop?.stopFindInPage()
+ $findInPage.set({ ...prev, query: '', matchOrdinal: 0, matchCount: 0 })
+
+ return
+ }
+
+ void window.hermesDesktop?.findInPage(query, { forward: true, findNext: false })
+}
+
+export function findNext(): void {
+ const { query } = $findInPage.get()
+
+ if (query) {
+ void window.hermesDesktop?.findInPage(query, { forward: true, findNext: true })
+ }
+}
+
+export function findPrevious(): void {
+ const { query } = $findInPage.get()
+
+ if (query) {
+ void window.hermesDesktop?.findInPage(query, { forward: false, findNext: true })
+ }
+}
+
+/** Called by the preload bridge when `found-in-page` fires on webContents. */
+export function updateFindResults(activeMatch: number, count: number): void {
+ const prev = $findInPage.get()
+ $findInPage.set({ ...prev, matchOrdinal: activeMatch, matchCount: count })
+}
+
+export function initFindInPageListener(): (() => void) | undefined {
+ return window.hermesDesktop?.onFoundInPage?.((result: { activeMatchOrdinal: number; count: number }) => {
+ updateFindResults(result.activeMatchOrdinal, result.count)
+ })
+}