Clean up API and small fixes
This commit is contained in:
parent
665cdb2881
commit
a80da338e4
13 changed files with 56 additions and 36 deletions
|
|
@ -65,9 +65,9 @@ impl ExampleDocument {
|
|||
let mut result = merged.text();
|
||||
for (i, cursor) in merged.cursors().iter().enumerate() {
|
||||
assert!(
|
||||
cursor.char_index <= result.len(), // equals in case of insert at the end
|
||||
cursor.char_index() <= result.len(), // equals in case of insert at the end
|
||||
"Cursor index out of bounds: {} > {} when testing for '{}.'",
|
||||
cursor.char_index,
|
||||
cursor.char_index(),
|
||||
result.len(),
|
||||
result
|
||||
);
|
||||
|
|
@ -75,7 +75,7 @@ impl ExampleDocument {
|
|||
result.insert(
|
||||
result
|
||||
.char_indices()
|
||||
.nth(cursor.char_index + i)
|
||||
.nth(cursor.char_index() + i)
|
||||
.map_or_else(|| result.len(), |(byte_index, _)| byte_index), /* find the utf8 char index of the insert
|
||||
* in byte index */
|
||||
'|',
|
||||
|
|
@ -94,10 +94,7 @@ impl ExampleDocument {
|
|||
let mut cursors = Vec::new();
|
||||
for (i, c) in text.chars().enumerate() {
|
||||
if c == '|' {
|
||||
cursors.push(CursorPosition {
|
||||
id: 0,
|
||||
char_index: i - cursors.len(),
|
||||
});
|
||||
cursors.push(CursorPosition::new(0, i - cursors.len()));
|
||||
}
|
||||
}
|
||||
cursors
|
||||
|
|
|
|||
|
|
@ -49,12 +49,14 @@ fn test_document_one_way_with_serialisation() {
|
|||
&*BuiltinTokenizer::Word,
|
||||
);
|
||||
|
||||
let serialised_left =
|
||||
serde_yaml::from_str(&serde_yaml::to_string(&left_operations.to_diff()).unwrap())
|
||||
.unwrap();
|
||||
let serialised_right =
|
||||
serde_yaml::from_str(&serde_yaml::to_string(&right_operations.to_diff()).unwrap())
|
||||
.unwrap();
|
||||
let serialised_left = serde_yaml::from_str(
|
||||
&serde_yaml::to_string(&left_operations.to_diff().unwrap()).unwrap(),
|
||||
)
|
||||
.unwrap();
|
||||
let serialised_right = serde_yaml::from_str(
|
||||
&serde_yaml::to_string(&right_operations.to_diff().unwrap()).unwrap(),
|
||||
)
|
||||
.unwrap();
|
||||
|
||||
let restored_left_operations =
|
||||
EditedText::from_diff(&parent, serialised_left, &*BuiltinTokenizer::Word).unwrap();
|
||||
|
|
|
|||
|
|
@ -60,7 +60,7 @@ fn test_diff() {
|
|||
let parent = "hello ";
|
||||
let changed = "world";
|
||||
|
||||
let result = diff(parent, &changed.into(), BuiltinTokenizer::Word);
|
||||
let result = diff(parent, &changed.into(), BuiltinTokenizer::Word).unwrap();
|
||||
|
||||
assert_eq!(result.len(), 2);
|
||||
let first: i64 = result[0].clone().try_into().unwrap();
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue