# agent_ui: Add selection to terminal thread \(\#57301\) · gitcafe/zed

[View on GitCafe](https://git.cafe/gitcafe/zed/commit/a565ab4457269ec0e5faa24940f939e5476ab8d3)

Repository: [gitcafe/zed](https://git.cafe/gitcafe/zed)

Visibility: public

Requested revision: a565ab4457269ec0e5faa24940f939e5476ab8d3

Requested commit: a565ab4457269ec0e5faa24940f939e5476ab8d3

Commit: a565ab4457269ec0e5faa24940f939e5476ab8d3

Tree: c597888ea2e99e36f1a320ac15672bc46ce972f6

Author: Ruslan Kiyanchuk

Committer: GitHub

## Message

```
agent_ui: Add selection to terminal thread (#57301)

## **NOTE:**
I'm new both to Rust and Zed, so it's mostly vibecoded alleged fix for
#57295, just as a PoC of expected behavior that works on macOS. So
please be critical and skeptical of the code, as it may not account for
many nuances and behavior on other platforms.

## Summary

- Fixes #57295: the `Add to Agent Thread` action (or `cmd->`) was a
silent
no-op when a terminal thread was the active conversation in the agent
panel.
- The action's deferred handler only routed through
`active_conversation_view()`,
which returns `None` for `BaseView::Terminal`, so the selection was
dropped.
- Extends the handler with an `else if` branch that, when a terminal
thread is
active, formats the selection as `@<rel-path>:<start>-<end>` (matching
the
  mention syntax CLI agents already understand) and pastes it into the
  terminal, then focuses the terminal so the user can edit/submit.

## Test plan

- [x] Select a range of lines in a buffer, open a terminal thread in the
agent
panel, invoke `Add to Agent Thread` from the context menu → the
formatted
      mention is pasted into the terminal.
- [x] Same flow via the `cmd->` keybinding on macOS.
- [x] Multiple selections in one buffer produce space-separated
mentions.
- [x] `cargo check -p agent_ui` and `./script/clippy -p agent_ui` pass.

## Demo

<img width="2928" height="1920" alt="ScreenShot 2026-05-20 at 21 03 27"
src="https://github.com/user-attachments/assets/dc29f380-a864-4c12-b454-bdb4201f5b8d"
/>


https://github.com/user-attachments/assets/9d3914d8-8ba2-4bcb-be43-78efb342d8a8


## Release Notes:

- Fixed `Add to Agent Thread` being a no-op when a terminal thread is
the active conversation in the agent panel

---------

Co-authored-by: Martin Ye <martin@zed.dev>
```

## Parents

- [f0a88e3698aedec0837a08154957489acbb22aa3](https://git.cafe/gitcafe/zed/commit/f0a88e3698aedec0837a08154957489acbb22aa3?format=markdown)

[Source at this commit](https://git.cafe/gitcafe/zed/tree/a565ab4457269ec0e5faa24940f939e5476ab8d3?format=markdown)
