# Fix \`closest_index_for_x\` to get correct offset when only 1 char \(\#23603\) · gitcafe/zed

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

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

Visibility: public

Requested revision: 3eba831de8a4292354d59a7e7b9dd2757db75114

Requested commit: 3eba831de8a4292354d59a7e7b9dd2757db75114

Commit: 3eba831de8a4292354d59a7e7b9dd2757db75114

Tree: 8b2b3cb22f12c3d379669d5b252110e88d5bd653

Author: Jason Lee

Committer: GitHub

## Message

````
Fix `closest_index_for_x` to get correct offset when only 1 char (#23603)

Release Notes:

- N/A

----------

This bug can easy to replay by `input` example, just enter 1 char and
click on the middle of the char, we can't move cursor to 0, it is always
be 1.

```bash
cargo run -p gpui --example input
```

## Before


https://github.com/user-attachments/assets/3239dd47-278e-4311-9757-5165d1ccd796

## After


https://github.com/user-attachments/assets/4e2c1500-0142-4e28-bf34-7ef1f4929925
````

## Parents

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

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