Skip to content

fix(browser): scope Cmd/Ctrl+F find to the focused split (#11348) - #11351

Merged
Jinwoo-H merged 6 commits into
stablyai:mainfrom
amirilovic:amirilovic/fix-11348-find-routes-to-browser
Jul 30, 2026
Merged

Jinwoo-H merged 6 commits into
stablyai:mainfrom
amirilovic:amirilovic/fix-11348-find-routes-to-browser

Conversation

@amirilovic

Copy link
Copy Markdown
Contributor

Summary

Fixes #11348.

In a terminal + browser split, pressing Cmd+F (macOS) / Ctrl+F (Windows/Linux) while the terminal was focused opened Find in the browser pane instead of find-in-terminal.

Root cause: the browser pane's renderer-path Find handler (BrowserPagePane in BrowserPane.tsx) is a window-global, capture-phase keydown listener that was armed on isActive — "am I the active tab within my own group?" — not on whether its split holds keyboard focus. BrowserPaneOverlayLayer computes isActive from isWorktreeActive && isActiveInGroup, which ignores activeGroupIdByWorktree (the focused split). So in a split the browser was isActive even while the terminal was focused, and its unscoped listener called preventDefault() + stopPropagation(), claiming the chord before the (correctly focus-scoped) terminal handler could act.

Fix: thread a focused-split signal (isFocused) from BrowserPaneOverlayLayer — derived from activeGroupIdByWorktree[worktreeId] — through BrowserPane → BrowserPagePane, and gate the renderer-path Find listener on isFocused instead of isActive. This mirrors how terminal leaves already gate global shortcuts via focusedGroupId in TabGroupSplitLayout.tsx. The IPC path (webview guest focused) is left on isActive — it only fires when the guest genuinely has focus, so it is already correct.

Screenshots

No visual change. Behavior-only: the Find bar now opens in whichever split (terminal or browser) holds keyboard focus.

Testing

  • pnpm lint (oxlint + oxfmt ran clean via pre-commit; targeted lint of browser-pane clean)
  • pnpm typecheck (tsconfig.tc.web.json clean)
  • pnpm test (browser-pane suite: 32 files / 181 tests pass)
  • pnpm build
  • Added regression tests in BrowserPaneOverlayLayer.test.tsx: an active browser pane is focused when its own group holds focus, and not focused when another split (e.g. the terminal) holds focus ([Bug]: Cmd/Ctrl+F opens Find in the browser pane instead of the focused terminal in a split #11348).

AI Review Report

Reviewed with an AI coding agent. Checks and outcomes:

  • Wrong-surface routing (the bug): confirmed the browser's window-global capture listener was the interceptor and that gating on the focused split resolves it without disturbing the terminal's already-scoped handler.
  • Cross-platform (macOS / Linux / Windows): the chord flows through keybindingMatchesAction('browser.find', …) which resolves Mod → metaKey on macOS and ctrlKey elsewhere — a single code path, so the fix applies uniformly. No e.metaKey hardcoding introduced; no platform-specific labels or paths touched.
  • Regressions to other call sites: BrowserPane gained an optional isFocused prop defaulting to isActive, so the floating-browser call sites (Terminal.tsx, FloatingBrowserSlot.tsx) are unchanged. SSH/remote pane (RemoteBrowserPagePane) has no Find handler and is untouched.
  • Guest-focused find: the IPC path is unchanged and still opens Find when the webview guest itself is focused.

Security Audit

No new input handling, command execution, path handling, auth, secrets, dependency, or IPC surface. The change only narrows the condition under which an existing renderer keydown listener is registered (fewer events claimed, not more). No IPC channels added or modified. No follow-up needed.

Notes

  • Behavior is symmetric: Find now targets whichever split holds focus. Clicking into the browser (chrome, address bar, or guest) focuses its group via the overlay's existing onPointerDown/onFocusCapture → focusGroup, so Cmd/Ctrl+F opens the browser find bar as before.
  • Related shape to [Bug]: Floating workspace shortcuts route to main workspace instead of floating panel #10288 (floating workspace shortcuts routing to the main workspace); this PR scopes only the terminal/browser split find path.

@coderabbitai

coderabbitai Bot commented Jul 29, 2026 •

Copy link
Copy Markdown
Contributor

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro Plus

Run ID: 2c50faf3-84c6-48e6-a717-3160874c7eb1

📥 Commits

Reviewing files that changed from the base of the PR and between 18337813c22fdec62ca5f5eb448c9f59c47cadb0 and e6faa2b.

📒 Files selected for processing (13)
  • src/main/browser/browser-guest-ui.test.ts
  • src/main/browser/browser-guest-ui.ts
  • src/main/browser/browser-manager.ts
  • src/preload/api-types.ts
  • src/preload/browser-find-subscriptions.test.ts
  • src/preload/browser-find-subscriptions.ts
  • src/preload/index.ts
  • src/renderer/src/components/browser-pane/BrowserPane.tsx
  • src/renderer/src/components/browser-pane/BrowserPaneOverlayLayer.test.tsx
  • src/renderer/src/components/browser-pane/BrowserPaneOverlayLayer.tsx
  • src/shared/browser-find-source.ts
  • src/shared/keybindings.test.ts
  • tests/e2e/browser-split-find-shortcut.spec.ts
🚧 Files skipped from review as they are similar to previous changes (1)
  • src/main/browser/browser-manager.ts

📝 Walkthrough

Walkthrough

Browser Find shortcuts now carry browser page and workspace identifiers through guest forwarding, IPC, and preload subscriptions. Browser overlays derive focused, inactive, and owned-target scopes and pass them to browser page panes to gate Find handling. Tests cover exact source dispatch, subscription cleanup, platform shortcuts, focused split routing, ownership across browser splits, and missing or stale focus state.

🚥 Pre-merge checks | ✅ 3 | ❌ 2

❌ Failed checks (2 warnings)

Check name Status Explanation Resolution
Out of Scope Changes check ⚠️ Warning The PR also changes unrelated preload APIs and runtime/feedback surfaces that are not required for #11348. Split those unrelated API and IPC changes into separate PRs or justify them within the linked issue scope.
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (3 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly summarizes the main fix: scoping Cmd/Ctrl+F to the focused split.
Description check ✅ Passed All required sections are present and the template is mostly complete, including summary, screenshots, testing, review, security, and notes.
Linked Issues check ✅ Passed The change routes Find to the focused split and matches #11348 across macOS, Windows, and Linux.
✨ Finishing Touches 💡 1
🛠️ Fix failing CI checks 💡
  • Fix failing CI checks

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@@ -154,12 +161,15 @@ const BrowserPaneOverlayLayer = memo(function BrowserPaneOverlayLayer({
{browserTabs.map((browserTab) => {
const assignment = assignments.get(browserTab.id)
const isActive = Boolean(isWorktreeActive && assignment && assignment.isActiveInGroup)
// Why: focused only when this browser's group is the focused split — not merely the active tab in its own group.
const isFocused = isActive && assignment?.groupId === focusedGroupId

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Cmd+F silently breaks when focusedGroupId is undefined

focusedGroupId is undefined when activeGroupIdByWorktree[worktreeId] hasn't been set yet (e.g. on a fresh worktree before any pointer/focus event). In that case assignment?.groupId === undefined is false for any real group string, so isFocused evaluates to false for every browser pane. Because BrowserPaneOverlayLayer always passes an explicit false (not omitting the prop), the ?? isActive fallback inside BrowserPane never fires — resolvedIsFocused stays false, and the Find listener is never registered. The shortcut silently does nothing until the user clicks the browser chrome and triggers focusGroup for the first time. A guard restores pre-fix behaviour for that uninitialized window: const isFocused = isActive && (focusedGroupId === undefined || assignment?.groupId === focusedGroupId). Or equivalently, pass undefined (omit the prop) when focusedGroupId is undefined so the existing fallback in BrowserPane takes over.

@greptile-apps

greptile-apps Bot commented Jul 29, 2026 •

Copy link
Copy Markdown

Greptile Summary

This PR fixes a split-pane focus bug where pressing Cmd/Ctrl+F while the terminal was focused incorrectly opened Find in the adjacent browser pane. The browser pane's window-global capture-phase keydown listener was gated on isActive (active in its own tab group) rather than on whether the browser's split held keyboard focus.

  • Introduces a BrowserFindShortcutScope discriminated union ('focused' | 'inactive' | 'owned-target') threaded from BrowserPaneOverlayLayer → BrowserPane → BrowserPagePane; the renderer-path Find listener is now gated on this scope instead of isActive.
  • Adds a BrowserFindSource (pageId + workspaceId) type and a new browser-find-subscriptions module so the IPC path (guest-focused Find) dispatches only to the exact browser page+workspace owner, preventing cross-pane bleed when multiple browser splits share the same renderer.
  • Introduces an 'owned-target' fallback scope for the uninitialized/stale focusedGroupId case: the listener stays registered but only claims the shortcut when the event target descends from its own overlay DOM element, so Find remains available without incorrectly stealing the chord from the terminal.

Confidence Score: 5/5

Safe to merge — the change only narrows the condition under which an existing global keydown listener claims the Find shortcut, and the IPC path is now routed by exact page+workspace identity instead of broadcast.

The root cause and fix are clearly analysed, the three code paths (renderer-scope, IPC routing, owned-target fallback) are each exercised by unit and e2e tests, all existing callers of onFindInBrowserPage are updated, and the optional findShortcutScope prop defaults to the pre-fix behaviour so floating-browser surfaces are unaffected.

Files Needing Attention: No files require special attention.

Important Files Changed

Filename Overview
src/renderer/src/components/browser-pane/BrowserPaneOverlayLayer.tsx Core fix: reads activeGroupIdByWorktree[worktreeId] as focusedGroupId, validates it against the live groups list, and derives a BrowserFindShortcutScope for each browser tab; correctly handles undefined/stale focusedGroupId via the 'owned-target' fallback.
src/renderer/src/components/browser-pane/BrowserPane.tsx Gates the renderer-path Find listener on findShortcutScope instead of isActive; adds 'owned-target' DOM-ancestry check via browserOverlayOwnsShortcutTarget; IPC path now subscribes with a typed BrowserFindSource for exact page+workspace routing.
src/preload/browser-find-subscriptions.ts New module implementing two-level (workspace → page) subscription map for browser Find IPC events; dispatch only reaches the exact matching callback set; cleanup correctly removes empty intermediate maps.
src/preload/index.ts Replaces the broadcast ipcRenderer listener with a single global dispatcher into browserFindSubscriptions; exposes browserFindSubscriptions.subscribe as the new onFindInBrowserPage API — the singleton registration pattern is safe for the preload lifetime.
src/main/browser/browser-guest-ui.ts IPC-path Find now sends a typed BrowserFindSource payload; if resolveWorkspaceId returns null (tab not yet registered), the event is intentionally dropped rather than broadcast — this is the correct safe-default behaviour.
src/shared/browser-find-source.ts New shared type BrowserFindSource with a runtime type guard isBrowserFindSource; guards correctly reject null, non-objects, arrays, and empty strings.
src/main/browser/browser-manager.ts One-line addition wiring the existing workspaceIdByPageId map into setupGuestShortcutForwarding; no other call sites exist for this function in production.
tests/e2e/browser-split-find-shortcut.spec.ts New e2e spec covering the primary regression (terminal focus steals Find), multi-browser split IPC routing, and the two focusedGroupId fallback scenarios (missing and stale).
src/renderer/src/components/browser-pane/BrowserPaneOverlayLayer.test.tsx New unit tests verify focused/inactive/owned-target scope assignment including the stale focusedGroupId case and split reordering; mock correctly exposes findShortcutScope via data attribute.
src/preload/browser-find-subscriptions.test.ts Tests exact-match dispatch semantics, malformed-source rejection, and cleanup of empty map entries — covers the subscription module's contract fully.
src/preload/api-types.ts onFindInBrowserPage signature updated to require a BrowserFindSource first argument; the web stub in web-preload-api.ts is a zero-argument noop that remains type-compatible.
src/main/browser/browser-guest-ui.test.ts Two new test cases for the IPC-path Find: forwards with the correct BrowserFindSource when workspace is registered, and drops silently when no workspace resolver is provided.
src/shared/keybindings.test.ts New test confirms browser.find maps to Command on macOS and Control on Linux/Windows, covering all three platforms.

Reviews (4): Last reviewed commit: "test(browser): focus split before Find r..." | Re-trigger Greptile

@AmethystLiang
AmethystLiang requested a review from OrcaWin July 29, 2026 16:49
@Jinwoo-H
Jinwoo-H force-pushed the amirilovic/fix-11348-find-routes-to-browser branch 2 times, most recently from 07fee35 to 1833781 Compare July 30, 2026 02:52

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🧹 Nitpick comments (1)
src/main/browser/browser-guest-ui.test.ts (1)

590-602: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick win

Exercise the missing-owner resolver path.

This test omits resolveWorkspaceId, so it does not cover the production path where the resolver exists but returns null for an unregistered page.

Proposed test adjustment
     setupGuestShortcutForwarding({
       browserTabId,
       guest: makeGuest(),
-      resolveRenderer: () => makeRenderer()
+      resolveRenderer: () => makeRenderer(),
+      resolveWorkspaceId: () => null
     })

ℹ️ Review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro Plus

Run ID: 8610534a-fdbc-420d-bb74-fd9c6b01efba

📥 Commits

Reviewing files that changed from the base of the PR and between 07fee35c39ae4b31063074577a8404c88dd560da and 18337813c22fdec62ca5f5eb448c9f59c47cadb0.

📒 Files selected for processing (13)
  • src/main/browser/browser-guest-ui.test.ts
  • src/main/browser/browser-guest-ui.ts
  • src/main/browser/browser-manager.ts
  • src/preload/api-types.ts
  • src/preload/browser-find-subscriptions.test.ts
  • src/preload/browser-find-subscriptions.ts
  • src/preload/index.ts
  • src/renderer/src/components/browser-pane/BrowserPane.tsx
  • src/renderer/src/components/browser-pane/BrowserPaneOverlayLayer.test.tsx
  • src/renderer/src/components/browser-pane/BrowserPaneOverlayLayer.tsx
  • src/shared/browser-find-source.ts
  • src/shared/keybindings.test.ts
  • tests/e2e/browser-split-find-shortcut.spec.ts

amirilovic and others added 6 commits July 29, 2026 20:25
)

The browser pane's renderer-path Find handler is a window-global
capture-phase keydown listener, but it armed on `isActive` (the active
tab within its own group) rather than on whether its split holds focus.
In a terminal+browser split, the browser was therefore `isActive` even
while the terminal held keyboard focus, so it swallowed Cmd/Ctrl+F and
opened find-in-page in the browser instead of find-in-terminal.

Thread a focused-split signal (`isFocused`) from BrowserPaneOverlayLayer
— derived from `activeGroupIdByWorktree` — down to the Find handler and
gate the listener on it. This mirrors how terminal leaves already gate
global shortcuts via `focusedGroupId` in TabGroupSplitLayout. Floating
browser panels omit the prop and fall back to `isActive`, preserving
their behavior. The IPC path (webview guest focused) is unchanged; it
only fires when the guest genuinely has focus.

Not platform-specific: the chord resolves through `keybindingMatchesAction`
(Mod -> metaKey on macOS, ctrlKey elsewhere), so the same path is fixed on
macOS, Linux, and Windows.

Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
@Jinwoo-H
Jinwoo-H force-pushed the amirilovic/fix-11348-find-routes-to-browser branch from 1833781 to e6faa2b Compare July 30, 2026 03:27
@Jinwoo-H
Jinwoo-H merged commit 5165cd1 into stablyai:main Jul 30, 2026
49 of 55 checks passed
enrick-dev pushed a commit to enrick-dev/orca that referenced this pull request Oct 15, 2026
) (stablyai#11351)

* fix(browser): scope Cmd/Ctrl+F find to the focused split (stablyai#11348)

The browser pane's renderer-path Find handler is a window-global
capture-phase keydown listener, but it armed on `isActive` (the active
tab within its own group) rather than on whether its split holds focus.
In a terminal+browser split, the browser was therefore `isActive` even
while the terminal held keyboard focus, so it swallowed Cmd/Ctrl+F and
opened find-in-page in the browser instead of find-in-terminal.

Thread a focused-split signal (`isFocused`) from BrowserPaneOverlayLayer
— derived from `activeGroupIdByWorktree` — down to the Find handler and
gate the listener on it. This mirrors how terminal leaves already gate
global shortcuts via `focusedGroupId` in TabGroupSplitLayout. Floating
browser panels omit the prop and fall back to `isActive`, preserving
their behavior. The IPC path (webview guest focused) is unchanged; it
only fires when the guest genuinely has focus.

Not platform-specific: the chord resolves through `keybindingMatchesAction`
(Mod -> metaKey on macOS, ctrlKey elsewhere), so the same path is fixed on
macOS, Linux, and Windows.

Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>

* fix(browser): preserve Find before split focus settles

* fix(browser): handle stale focused split IDs

* fix(browser): route guest Find to source page

* test(browser): wait for split address bar

* test(browser): focus split before Find routing

---------

Co-authored-by: Claude Opus 4.8 (1M context) <[email protected]>
Co-authored-by: OrcaWin <[email protected]>
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.

[Bug]: Cmd/Ctrl+F opens Find in the browser pane instead of the focused terminal in a split

3 participants