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
This commit is contained in:
Jason Lee 2025-01-28 14:18:18 +08:00 committed by GitHub
parent 02503cf3be
commit 3eba831de8
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -90,6 +90,14 @@ impl LineLayout {
}
}
if self.len == 1 {
if x > self.width / 2. {
return 1;
} else {
return 0;
}
}
self.len
}