editor: Fix multi-line cursor expansion when multi-byte characters are involved (#51780)

Closes #51740 

The multi-line cursor expansion operates off of byte offsets, instead of
character offsets, so multi-byte characters like the umlaut cause the
multi-line cursors to be weirdly offset. To fix we just convert the
expansion logic to rely on utf16 characters instead of bytes.

before behavior:


https://github.com/user-attachments/assets/320e24e9-0fdd-4d16-a9e8-ca17c9e21ff2

after behavior: 


https://github.com/user-attachments/assets/c4f0334b-dffc-4530-91ee-577b4fab75dd

+ test to verify functionality.

Before you mark this PR as ready for review, make sure that you have:
- [x] Added a solid test coverage and/or screenshots from doing manual
testing
- [x] Done a self-review taking into account security and performance
aspects
- [x] Aligned any UI changes with the [UI
checklist](https://github.com/zed-industries/zed/blob/main/CONTRIBUTING.md#uiux-checklist)

Release Notes:

- editor: fixed multi-line cursor expansion dealing with multi-byte
characters.

---------

Co-authored-by: Kirill Bulatov <mail4score@gmail.com>
This commit is contained in:
Finn EitreimandKirill Bulatov authored and GitHub committed 2026-03-19 16:21:03 +00:00
1 parent e314c023b3
commit d94aa26ac5
5 files changed
+163 -55

No files matched your search

+5
View File
@@ -5188,6 +5188,11 @@ impl MultiBufferSnapshot {
}
}
pub fn line_len_utf16(&self, row: MultiBufferRow) -> u32 {
self.clip_point_utf16(Unclipped(PointUtf16::new(row.0, u32::MAX)), Bias::Left)
.column
}
pub fn buffer_line_for_row(
&self,
row: MultiBufferRow,