7.4 KiB
Layout-aware find in editable Monaco editors
Problem
Issue #7953 reports that Cmd+F can type f into a TypeScript file instead of opening find on macOS.
Orca's editable Monaco surfaces currently install its layout-aware save shortcut through editor-shortcuts.ts (src/renderer/src/components/editor/editor-shortcuts.ts:18), but leave find entirely to Monaco's internal keycode dispatch. Orca already declares editor.find as Mod+F (src/shared/keybindings.ts:784) and its matcher resolves logical keys before physical-code fallback (src/shared/keybindings.ts:2041).
A real Electron repro sends a macOS event with logical key f, physical code KeyU, and virtual key code U, as produced by a non-QWERTY layout. Monaco leaves its find widget closed. The equivalent QWERTY KeyF event opens it.
Root cause
Monaco's built-in find keybinding follows the physical/virtual keycode delivered by Chromium. Orca's shortcut system is layout-aware, but its editable Monaco integrations do not use it for find. On layouts where the key that produces f is not physical KeyF, Monaco misses the chord and Native Edit Context remains in editing mode.
Non-goals
- Reimplementing Monaco's find widget, match navigation, or search state.
- Changing find behavior in markdown preview, rich markdown, PDF, browser, terminal, or file search.
- Changing find behavior in read-only diff surfaces.
- Reworking all Monaco keybindings or making Monaco defaults fully obey shortcut unbinding in this patch.
- Adding telemetry for a local keyboard action.
Design
- Add a focused editor find installer beside the existing save installer in
editor-shortcuts.ts. It matcheseditor.findthrougheditorShortcutMatches, consumes every matched event before it reaches Native Edit Context or Monaco, and invokes a supplied callback only for the initial, non-repeat keydown. Repeat events must still be prevented and propagation-stopped so Monaco's QWERTY binding cannot reopen/reset the widget. - Install that handler on every editable Monaco container in the source editor, editable diff views, and notebook code cells. Run that editor's existing
actions.findaction and dispose the bridge from its existing teardown callback. - Add unit coverage at the DOM-listener seam for logical
fwith a non-KeyFphysical code, QWERTY/default behavior, repeat suppression, unrelated typing, and cleanup. - Preserve an Electron regression loop that drives both QWERTY and layout-aware raw key events against a real
.tseditor and verifies the existing Monaco find widget becomes visible without dirtying the file.
Data flow
- macOS/Linux/Windows keydown reaches the focused editable Monaco container.
editorShortcutMatches('editor.find', event)resolves the active platform, user bindings, modifiers, and logical key.- On match, Orca consumes the DOM event and calls Monaco's existing
actions.findaction. - Monaco owns the visible find widget and focus exactly as before.
Edge cases
- Auto-repeat must be consumed without invoking find again; returning early before prevention would let Monaco handle a repeated QWERTY
KeyFevent. - Ordinary unmodified
ftyping and unrelated shortcuts must continue to Monaco unchanged. - A removed/disposed source editor, diff pane, or notebook cell must not retain the listener.
- QWERTY
Cmd/Ctrl+Fmust still open the same Monaco widget once, not twice. - User-configured bindings accepted by Orca's
editor.findmatcher should open find; Monaco's own default bindings remain outside the scope of this patch. - The behavior is renderer-local and does not read files or execute commands, so local, SSH, and Remote Orca files share the same path.
Test plan
- Unit:
editor-shortcuts.test.tsdispatches keyboard events through a real element and parameterizes the shared bridge across macOS (metaKey) and Linux/Windows (ctrlKey) using logicalfwith physicalKeyU. It also asserts QWERTY/default handling, matched-repeat prevention without a second callback, unrelated typing, and disposal behavior used by every editable Monaco integration. - Electron: open a disposable
.tsfile and driveCmd+F/Ctrl+Fusing the platform modifier; assert.find-widget.visible, focused find input, unchanged source text, and clean editor state. - Electron layout regression: on macOS, dispatch logical
fwith non-QWERTY physical/virtual key identity; assert the same find state and unchanged source text. - Adjacent smoke: dismiss find, type a normal character, and verify it edits the file rather than reopening find.
- Static: run focused Vitest,
pnpm typecheck, andpnpm lint.
UI quality bar
No new UI. The existing Monaco find widget must appear in its current position and styling, focus its input, and leave the editor content unchanged. No overlap, clipping, duplicate widget, or focus flicker is acceptable.
Review screenshots
- QWERTY/default shortcut with the existing Monaco find widget visible in a
.tseditor. - Non-QWERTY logical-
fregression path with the same find widget visible and source text unchanged. - Adjacent ordinary typing state after find is dismissed, showing the source editor still accepts text normally.
Rollout
- Add failing unit coverage for the layout-aware find installer contract.
- Implement the installer in
editor-shortcuts.ts. - Wire it to each editable Monaco surface's existing find action and lifecycle cleanup.
- Run focused tests, typecheck, lint, and the Electron QWERTY/layout/typing scenarios.
Lightweight Eng Review
- Scope: Kept to one shared shortcut installer and the existing mount/teardown seams for source editors, editable diff panes, and notebook code cells; no new find implementation or global shortcut interception.
- Architecture/data flow: The renderer-local Monaco container owns the keydown. Orca's canonical matcher resolves the logical key, while Monaco continues to own widget state and rendering. No main/preload/IPC, persistence, network, SSH, or provider boundary changes.
- Failure modes covered:
- Non-QWERTY logical key differs from physical/virtual keycode.
- QWERTY double handling.
- Auto-repeat escaping to Monaco's native QWERTY handler.
- Listener surviving editor disposal.
- Ordinary typing being consumed.
- Custom
editor.findchord accepted by Orca but not Monaco.
- Test coverage required:
- DOM-listener unit tests in
src/renderer/src/components/editor/editor-shortcuts.test.ts, parameterized for Darwin/Meta, Linux/Ctrl, and Windows/Ctrl. - Electron-visible QWERTY and layout-aware
.tsscenarios. - Adjacent ordinary typing smoke test.
- DOM-listener unit tests in
- Performance/blast radius: One capture listener per mounted editable Monaco editor, doing a constant-time keybinding comparison only for events within that editor. Multiple mounted diff sections do not fan out because each listener is scoped to its own container. Listeners are removed with Monaco disposal; no polling, scans, IPC, storage, or render-loop work.
- UI quality bar: Existing Monaco find widget only; verify focus, unchanged source text, no duplicate opening, and unchanged styling against
docs/STYLEGUIDE.md. - Required review screenshots:
- Default QWERTY find-open state.
- Non-QWERTY logical-key find-open state.
- Find-dismissed ordinary typing state.
- Residual risks: Monaco's internal default bindings remain active when a user explicitly rebinds
editor.find; fully suppressing/remapping Monaco's native keybinding table is a separate, larger change.