diff --git a/backend/reconcile/src/operation_transformation.rs b/backend/reconcile/src/operation_transformation.rs index 30e32502..a71bc65a 100644 --- a/backend/reconcile/src/operation_transformation.rs +++ b/backend/reconcile/src/operation_transformation.rs @@ -160,7 +160,7 @@ mod test { "hi ", "hi there you ", "hi there my friend ", - "hi there you my friend ", + "hi there my friend you ", ); test_merge_both_ways("a", "a b c", "a b c d", "a b c d"); diff --git a/backend/reconcile/src/operation_transformation/edited_text.rs b/backend/reconcile/src/operation_transformation/edited_text.rs index d3ae3832..8a7013e4 100644 --- a/backend/reconcile/src/operation_transformation/edited_text.rs +++ b/backend/reconcile/src/operation_transformation/edited_text.rs @@ -211,7 +211,16 @@ where usize::from(matches!(operation.operation, Operation::Delete { .. })), // Make sure that the ordering is deterministic regardless which text // is left or right. - operation.operation.get_hash(), + match &operation.operation { + Operation::Insert { text, .. } => text + .iter() + .map(super::super::tokenizer::token::Token::original) + .collect::(), + Operation::Delete { + deleted_character_count, + .. + } => deleted_character_count.to_string(), + }, ) }, ) @@ -285,7 +294,7 @@ mod tests { let original = "hello world! ..."; let left = "Hello world! I'm Andras."; let right = "Hello world! How are you?"; - let expected = "Hello world! I'm Andras. How are you?"; + let expected = "Hello world! How are you? I'm Andras."; let operations_1 = EditedText::from_strings(original, left); let operations_2 = EditedText::from_strings(original, right); diff --git a/backend/reconcile/src/operation_transformation/operation.rs b/backend/reconcile/src/operation_transformation/operation.rs index 73fa6140..d0d285b0 100644 --- a/backend/reconcile/src/operation_transformation/operation.rs +++ b/backend/reconcile/src/operation_transformation/operation.rs @@ -1,8 +1,5 @@ use core::fmt::{Debug, Display}; -use std::{ - hash::{DefaultHasher, Hash, Hasher}, - ops::Range, -}; +use std::ops::Range; #[cfg(feature = "serde")] use serde::{Deserialize, Serialize}; @@ -39,28 +36,6 @@ where }, } -impl Hash for Operation -where - T: PartialEq + Clone + std::fmt::Debug, -{ - fn hash(&self, state: &mut H) { - match self { - Operation::Insert { index, text } => { - index.hash(state); - text.iter().for_each(|token| token.original().hash(state)); - } - Operation::Delete { - index, - deleted_character_count, - .. - } => { - index.hash(state); - deleted_character_count.hash(state); - } - } - } -} - impl Operation where T: PartialEq + Clone + std::fmt::Debug, @@ -315,13 +290,6 @@ where } } } - - /// Gets the hash of the operation based on the indexes and original text. - pub fn get_hash(&self) -> u64 { - let mut hasher = DefaultHasher::new(); - self.hash(&mut hasher); - hasher.finish() - } } impl Display for Operation diff --git a/backend/sync_lib/tests/web.rs b/backend/sync_lib/tests/web.rs index eca585b6..e45cbea6 100644 --- a/backend/sync_lib/tests/web.rs +++ b/backend/sync_lib/tests/web.rs @@ -25,9 +25,9 @@ fn test_base64_to_bytes_error() { #[wasm_bindgen_test(unsupported = test)] fn merge_text() { let left = b"hello "; - let right = b"world "; + let right = b"world"; let result = merge(b"", left, right); - assert!(result == b"hello world ".to_vec() || result == b"world hello ".to_vec()); + assert_eq!(result, b"hello world"); } #[wasm_bindgen_test(unsupported = test)]