Files
zed/crates
David Jensen d39178f6c9 agent_ui: Keep focus when background threads auto-send queued messages (#66787)
## Summary

Typing in one conversation no longer loses keyboard focus when a
different, background conversation finishes a turn and automatically
sends its next queued follow-up. Sending a queued message yourself (Send
Now, or fast-tracking the next queued message by pressing Send in the
empty composer) still returns focus to that thread's composer.

The focus decision stays in the shared queued-entry dispatch. Each
caller now passes an explicit source (automatic or manual), and the
dispatch focuses the composer only for manual sends. Queue validation,
cancellation, sending and error recovery are unchanged.

Closes #66416

## Testing

Automated checks run locally on the initial fixed implementation:

- New regression test for automatic sends failed without the fix (at the
foreground composer focus assertion) and passes with it. A second new
test covers manual sends keeping focus. Both passed scheduler seeds
0-19.
- All `agent_ui` and `gpui_apple` tests passed, `cargo fmt --check` and
`./script/clippy -p agent_ui -p gpui_apple` passed, and a full
development build succeeded.
- The full workspace suite and Windows/Linux validation were not run
locally.

Automated native desktop UI test on macOS with a local simulated ACP
agent (not a real external agent or model, and not a human manual test):
thread A had two queued follow-ups, and numbered chunks 01-18 were typed
into thread B one character at a time. A's turns completed mid-typing
and each follow-up auto-submitted, with no clicks, refocuses or window
activations. B's draft was then submitted and received exactly `Typing
in B: 01 02 03 04 05 06 07 08 09 10 11 12 13 14 15 16 17 18`.

After the follow-up change that passes an explicit dispatch source (an
internal refactor of the same behavior), all `agent_ui` and `gpui_apple`
tests, both focus tests across seeds 0-19, Clippy and formatting were
rerun and passed. The development app and the desktop test above were
not rebuilt or repeated for that change, and the screenshots come from
the initial implementation.

To reproduce:

1. Open two threads, A and B, in the same window.
2. In A, send a message and, while it generates, queue two follow-ups.
3. Switch to B and start typing continuously.
4. When A's turn finishes, its next follow-up is sent. Typing in B
should continue uninterrupted.

AI assistance was used to prepare this change and its description.

## Self-review

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

## Screenshots

<img width="800" height="125" alt="Image"
src="https://github.com/user-attachments/assets/69e7a496-d379-40de-bd0f-9febd5786ff7"
/>

Thread A – Queued followups

<img width="800" height="155" alt="Image"
src="https://github.com/user-attachments/assets/67a5b79c-de25-48f6-9f9b-eeec534b2398"
/>


Thread B – Typing focus retained

Release Notes:

- Fixed typing in an agent thread losing focus when another thread
automatically sends its queued messages.

---------

Co-authored-by: David Jensen <288440181+daejey@users.noreply.github.com>
2026-11-16 13:29:34 +00:00
..
…
2026-11-11 19:41:39 +00:00
…
2026-10-26 13:46:57 +00:00
…
…
…
…
…
…
…