Fix paste into browser routing to terminal text box (text box beta)

Closed
AU
2mo ago
+182-3

Fixes #6380

Problem

With a terminal and a browser pane side by side and text box beta enabled, pasting (Cmd+V) into the focused browser pasted into the terminal's text box instead of the browser.

Only paste was affected — not copy/cut/select-all, and not typing — and only with the text box beta enabled. That asymmetry is the tell.

Root cause

Two complementary issues:

  1. Paste was missing from the browser document-editing commands. BrowserDocumentEditingCommandEquivalent listed copy, cut, and selectAll but not paste. Those three preflight into the focused web view (shouldRouteBrowserDocumentEditingCommandEquivalentThroughWebContentFirst) before cmux's menu fallback, so the focused browser claims them first. Cmd+V was never routed there, so it fell through to the original NSWindow.performKeyEquivalent.

  2. performKeyEquivalent is broadcast to every view in the window, not just the first responder. TextBoxInputTextView overrides it and claimed Cmd+C/X/V (and undo/redo) unconditionally. So in the fall-through broadcast, the unfocused terminal text box grabbed Cmd+V before the menu could route it to the browser — pasting into the text box. Copy/cut weren't affected because they were already routed to web content first (issue 1); typing wasn't affected because keyDown only reaches the first responder.

Fix

  • ShortcutRoutingSupport.swift — add paste (Cmd+V) to BrowserDocumentEditingCommandEquivalent so the focused web view claims it first, exactly like copy/cut/select-all. Cmd+V only; Cmd+Shift+V (paste-and-match-style) keeps its dedicated path because matches requires an exact modifier match.
  • TextBoxInput.swift — gate the text box's standard edit/undo shortcuts in performKeyEquivalent on the text view actually owning first responder, so an unfocused text box no longer steals copy/cut/paste/undo from the focused browser (web content or omnibar) or terminal. The focus shortcut path is intentionally left ungated so it can still focus the text box.

Tests

Two-commit red/green:

  • Commit 1 (failing): testBrowserPasteCommandRoutesThroughWebContentFirst and testTextBoxDeclinesPasteShortcutWhenNotFirstResponder.
  • Commit 2 (fix + guards): plus testTextBoxHandlesPasteShortcutWhenFirstResponder (normal paste still works when focused) and testBrowserPlainTextPasteCommandIsNotADocumentEditingPaste (Cmd+Shift+V keeps its own path).

Localization

No user-facing strings, menus, settings rows, shortcut metadata, alerts, tooltips, or docs changed — Cmd+V is a standard system command (not a cmux-owned KeyboardShortcutSettings shortcut), matching the existing copy/cut/select-all pattern. No localization updates required.

🤖 Generated with Claude Code


Summary by cubic

Fixes Cmd+V being intercepted by the terminal text box when Text Box Beta is enabled. Paste now goes to the focused browser; the text box only handles edit shortcuts when it’s first responder (fixes #6380).

  • Bug Fixes
    • Added paste (Cmd+V) to BrowserDocumentEditingCommandEquivalent so the focused web view claims it first; Cmd+Shift+V keeps its dedicated path.
    • Gated TextBoxInputTextView.performKeyEquivalent so copy/cut/paste/undo/redo run only when the text box owns first responder; the focus shortcut stays ungated.
    • Moved regression tests to Swift Testing covering browser preflight, first-responder gating, Cmd+Shift+V behavior, and paste while the text box is focused.

Summary by CodeRabbit

  • Bug Fixes
    • Improved keyboard shortcut routing so paste now goes to the currently focused web content instead of an unrelated text field.
    • Text boxes no longer intercept editing shortcuts unless they are the active input, preventing unfocused fields from handling copy, cut, paste, undo, and redo.
    • Added coverage for paste and paste-as-plain-text shortcut behavior to help ensure consistent handling.