# agent: Fix inline assistant focusing behavior for cursor placement \(\#29998\) · gitcafe/zed

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

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

Visibility: public

Requested revision: 0ad582eec46da97b6f0a9b119b37b0dd45351fa9

Requested commit: 0ad582eec46da97b6f0a9b119b37b0dd45351fa9

Commit: 0ad582eec46da97b6f0a9b119b37b0dd45351fa9

Tree: 0f8b3183119c79b539dc5bd2f4d376eecaf73aad

Author: Umesh Yadav

Committer: GitHub

## Message

```
agent: Fix inline assistant focusing behavior for cursor placement (#29998)

Ref: https://github.com/zed-industries/zed/pull/29919

This PR improves how inline assistants are detected and focused based on
cursor position.

### Problem
The current implementation has inconsistent behavior:
- When selecting text within an inline assistant's range, the assistant
properly focuses
- When placing a cursor on a line containing an assistant (without
selection), a new assistant is created instead of focusing the existing
one

### Solution
Enhanced the assistant detection logic to:
- Check if the cursor is anywhere within the line range of an existing
assistant
- Maintain the same behavior for both cursor placement and text
selection
- Convert both cursor position and assistant ranges to points for better
line-based comparison

This creates a more intuitive editing experience when working with
inline assistants, reducing the creation of duplicate assistants when
the user intends to interact with existing ones.


https://github.com/user-attachments/assets/55eb80d1-76a7-4d42-aac4-2702e85f13c4

Release Notes:

- agent: Improved inline assistant behavior to focus existing assistants
when cursor is placed on their line, matching selection behavior

---------

Co-authored-by: Bennet Bo Fenner <bennet@zed.dev>
```

## Parents

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

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