From c1f72328ffaf4a4d5840ecb37dba1dfb8c3fa760 Mon Sep 17 00:00:00 2001 From: Antonio Scandurra Date: Sun, 23 Jul 2023 18:50:57 +0200 Subject: [PATCH] Avoid taking fragment when not fully consuming it --- crates/crdb/src/operations.rs | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/crates/crdb/src/operations.rs b/crates/crdb/src/operations.rs index 023647c6e8..552b977dd2 100644 --- a/crates/crdb/src/operations.rs +++ b/crates/crdb/src/operations.rs @@ -116,13 +116,13 @@ impl Edit { parent_fragment.insertion_id, parent_fragment.insertion_subrange, ) { - if let Some(fragment) = current_fragment.take() { + if let Some(fragment) = current_fragment.as_ref() { // Advance to fragment_location if it is greater than the location of the current fragment, if *fragment_location > fragment.location { // Flush the remainder of current fragment. if !fragment.insertion_subrange.is_empty() { - new_ropes.push_fragment(&fragment, fragment.visible()); - new_fragments.push(fragment, &()); + new_ropes.push_fragment(fragment, fragment.visible()); + new_fragments.push(fragment.clone(), &()); } old_fragments.next(&()); @@ -143,10 +143,11 @@ impl Edit { } // If the edit starts at the end of the current fragment, flush it. - if let Some(fragment) = current_fragment.take() { + if let Some(fragment) = current_fragment.as_ref() { if fragment.insertion_id == range.start_insertion_id && fragment.insertion_subrange.end == range.start_offset_in_insertion { + let fragment = current_fragment.take().unwrap(); new_ropes.push_fragment(&fragment, fragment.visible()); new_fragments.push(fragment, &()); old_fragments.next(&());