# agent_ui: Fix panic when inserting context prefix with multi-byte characters \(\#48179\) · gitcafe/zed

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

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

Visibility: public

Requested revision: 9ee0f08944f4191111b9b304375bdbf103ffb6e1

Requested commit: 9ee0f08944f4191111b9b304375bdbf103ffb6e1

Commit: 9ee0f08944f4191111b9b304375bdbf103ffb6e1

Tree: 2a7bde8c452128b17defaea818b60cf6e1ae9bef

Author: Smit Barmase

Committer: GitHub

## Message

```
agent_ui: Fix panic when inserting context prefix with multi-byte characters (#48179)

Closes ZED-4R9

Introduced in https://github.com/zed-industries/zed/pull/47768

The `insert_context_prefix` function was using byte offsets to check if
the prefix already exists at the cursor. This caused a panic with
multi-byte characters like emojis. Now uses character counts instead.

Release Notes:

- Fixed a crash in the Agent Panel when inserting context mentions with
emojis in the message editor.
```

## Parents

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

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