From 46d2e0c485e7a51e32520923a9abd672856323e7 Mon Sep 17 00:00:00 2001 From: Andras Schmelczer Date: Sun, 22 Jun 2025 09:48:26 +0100 Subject: [PATCH] Remove start_index from sorting --- src/operation_transformation/edited_text.rs | 6 +++++- src/operation_transformation/ordered_operation.rs | 13 ++----------- 2 files changed, 7 insertions(+), 12 deletions(-) diff --git a/src/operation_transformation/edited_text.rs b/src/operation_transformation/edited_text.rs index 56254a0..6aea48e 100644 --- a/src/operation_transformation/edited_text.rs +++ b/src/operation_transformation/edited_text.rs @@ -123,7 +123,11 @@ where let (side, OrderedOperation { operation, order }, maybe_other_operation) = match (maybe_left_op.clone(), maybe_right_op.clone()) { (Some(left_op), Some(right_op)) => { - if left_op < right_op { + if left_op + .get_sort_key(seen_left_length) + .partial_cmp(&right_op.get_sort_key(seen_right_length)) + == Some(std::cmp::Ordering::Less) + { (Side::Left, left_op, maybe_right_op.clone()) } else { (Side::Right, right_op, maybe_left_op.clone()) diff --git a/src/operation_transformation/ordered_operation.rs b/src/operation_transformation/ordered_operation.rs index 8878c45..c404079 100644 --- a/src/operation_transformation/ordered_operation.rs +++ b/src/operation_transformation/ordered_operation.rs @@ -17,7 +17,7 @@ impl OrderedOperation where T: PartialEq + Clone + std::fmt::Debug, { - pub fn get_sort_key(&self) -> (usize, usize, usize, String) { + pub fn get_sort_key(&self, insertion_index: usize) -> (usize, usize, usize, String) { ( self.order, match &self.operation { @@ -25,7 +25,7 @@ where Operation::Insert { .. } => 2, Operation::Equal { .. } => 3, }, - self.operation.start_index(), + insertion_index, // Make sure that the ordering is deterministic regardless of which text // is left or right. match &self.operation { @@ -41,12 +41,3 @@ where ) } } - -impl PartialOrd for OrderedOperation -where - T: PartialEq + Clone + std::fmt::Debug, -{ - fn partial_cmp(&self, other: &Self) -> Option { - self.get_sort_key().partial_cmp(&other.get_sort_key()) - } -}