Files
zed/crates/gpui_macos
Nathan Sobo d31d1074a0 gpui: Fix focus, key equivalent and mouse issues with native views (#67316)
## Summary

Follow-up to #67311, fixing issues a review found in GPUI's native view
support after it merged. All of them affect only windows that show a
native view.

- **A native view that declines keyboard input could recurse without
end.** AppKit answers `YES` to `makeFirstResponder:` even when the view
declines, leaving the window itself as first responder, and GPUI then
asked the same view again from inside the request. The window now checks
where first responder ended up, gives keyboard input to the GPUI view
when the native view didn't take it, and doesn't ask that view again
until it takes input itself or GPUI's focus moves. Reconciling makes at
most two requests.
- **With two native views, a key equivalent could be performed by the
one without keyboard input.** The window asked its superclass, which
searches the whole view hierarchy. It now offers the key equivalent to
the view that holds first responder, and native views sit in a container
that declines key equivalents so AppKit's own search no longer reaches
them.
- **A native view painted more than once left an invisible input
blocker.** Every occurrence inserted a blocking hitbox, though only one
is shown. Only the first-painted visible occurrence blocks now, and the
scene keeps the first occurrence in paint order rather than draw order.
- **A pending multi-key binding stayed armed across a key the view
consumed.** With `cmd-k o` bound, `cmd-k`, then `x` typed into the page,
then `o` still fired the binding. A key that doesn't continue the
pending binding now ends it the way its timeout does.
- **Mouse presses were attributed to a native view from GPUI geometry
alone, and tracked with one flag.** A press on an AppKit control placed
over a native view was also forwarded to GPUI, and with two buttons held
the first release cleared the flag for both. The window now asks
AppKit's hit test which view receives the press, and tracks owed
releases per button.

Not changed: native views are still missing from the window's
accessibility tree, because AccessKit's adapter on the content view
replaces its accessibility children. Moving the adapter to the GPUI view
would change accessibility for every window, and the GPUI view covers
the window, so hit-testing would likely still land in AccessKit's tree.
That needs its own change and a VoiceOver pass.

## Testing

- `cargo test -p gpui -p gpui_macos --lib` passes (457 and 18 tests).
New or extended unit tests cover the declined-view policy, per-button
release tracking, the repeated native view's hit-testing and scene
position, and the pending-binding behaviour; each failed against the
previous code.
- The AppKit behaviours relied on (first responder after a declined
request, the key-equivalent search skipping a declining container, the
hit-test recipient) were confirmed with an offscreen probe.
- Not yet run in an app with a real `WKWebView`: page shortcuts,
reserved bindings, two native views, and a click on a control over a
page.

## Self-review

- [x] I've reviewed my diff for quality, security, reliability, and
performance.
- [ ] UI changes follow the
[checklist](https://zed.dev/docs/development/ui-checklist).
- [x] Tests cover the new or changed behavior.

Release Notes:

- N/A
- [GPUI] Fixed a native view that declines keyboard input causing
unbounded recursion.
- [GPUI] Fixed key equivalents reaching a native view without keyboard
input, an unshown repeat of a native view blocking mouse input, a
pending multi-key binding surviving a key the native view used, and
mouse presses on controls over a native view being forwarded to GPUI.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

---------

Co-authored-by: Claude Fable 5.2 <noreply@anthropic.com>
2026-11-22 13:02:39 +00:00
..