Fix utf-8 cursor test

This commit is contained in:
Andras Schmelczer 2025-04-05 14:47:13 +01:00
parent 123d03fbed
commit 9399a335c1
No known key found for this signature in database
GPG key ID: FC8F2C3D3D1A718C

View file

@ -63,7 +63,16 @@ impl ExampleDocument {
fn text_with_cursors_to_string(text: &TextWithCursors<'_>) -> String {
let mut result = text.text.clone().into_owned();
for (i, cursor) in text.cursors.iter().enumerate() {
result.insert(cursor.char_index + i, '|');
result.insert(
result
.char_indices()
.skip(cursor.char_index + i)
.next()
.map(|(byte_index, _)| byte_index)
.unwrap_or_else(|| result.len()), /* find the utf8 char index of the insert
* in byte index */
'|',
);
}
result
}