From 7c081e893960295bf81d71b889863fc3e4f62506 Mon Sep 17 00:00:00 2001 From: Andras Schmelczer Date: Sun, 13 Apr 2025 22:21:38 +0100 Subject: [PATCH] Fix out of bounds cursors in case of trailing delete --- .../reconcile/src/operation_transformation/edited_text.rs | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/backend/reconcile/src/operation_transformation/edited_text.rs b/backend/reconcile/src/operation_transformation/edited_text.rs index 0ef6c66e..0f136fe7 100644 --- a/backend/reconcile/src/operation_transformation/edited_text.rs +++ b/backend/reconcile/src/operation_transformation/edited_text.rs @@ -309,7 +309,13 @@ where let last_index = merged_operations .iter() - .last() + .filter(|operation| { + matches!( + operation.operation, + Operation::Insert { .. } | Operation::Equal { .. } + ) + }) + .next_back() .map_or(0, |op| op.operation.end_index()); for cursor in left_cursors.chain(right_cursors) {