From 9399a335c1d2908a59bacbf21c0eecf10cb07588 Mon Sep 17 00:00:00 2001 From: Andras Schmelczer Date: Sat, 5 Apr 2025 14:47:13 +0100 Subject: [PATCH] Fix utf-8 cursor test --- backend/reconcile/tests/example_document.rs | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/backend/reconcile/tests/example_document.rs b/backend/reconcile/tests/example_document.rs index 98d68a3d..3d866c1b 100644 --- a/backend/reconcile/tests/example_document.rs +++ b/backend/reconcile/tests/example_document.rs @@ -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 }