Skip to content

Commit c61b4d0

Browse files
committed
fix: CI format error
1 parent 61d181b commit c61b4d0

File tree

4 files changed

+49
-6
lines changed

4 files changed

+49
-6
lines changed

shared-lib/lib-ot/src/core/document/document_operation.rs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
use crate::core::document::position::Position;
22
use crate::core::{NodeAttributes, NodeData, TextDelta};
33

4+
#[derive(Clone)]
45
pub enum DocumentOperation {
56
Insert(InsertOperation),
67
Update(UpdateOperation),
@@ -31,24 +32,31 @@ impl DocumentOperation {
3132
}),
3233
}
3334
}
35+
pub fn transform(_a: &DocumentOperation, b: &DocumentOperation) -> DocumentOperation {
36+
b.clone()
37+
}
3438
}
3539

40+
#[derive(Clone)]
3641
pub struct InsertOperation {
3742
pub path: Position,
3843
pub nodes: Vec<NodeData>,
3944
}
4045

46+
#[derive(Clone)]
4147
pub struct UpdateOperation {
4248
pub path: Position,
4349
pub attributes: NodeAttributes,
4450
pub old_attributes: NodeAttributes,
4551
}
4652

53+
#[derive(Clone)]
4754
pub struct DeleteOperation {
4855
pub path: Position,
4956
pub nodes: Vec<NodeData>,
5057
}
5158

59+
#[derive(Clone)]
5260
pub struct TextEditOperation {
5361
pub path: Position,
5462
pub delta: TextDelta,

shared-lib/lib-ot/src/core/document/position.rs

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,38 @@ impl Position {
55
pub fn is_empty(&self) -> bool {
66
self.0.is_empty()
77
}
8+
pub fn len(&self) -> usize {
9+
self.0.len()
10+
}
11+
}
12+
13+
impl Position {
14+
// delta is default to be 1
15+
pub fn transform(pre_insert_path: &Position, b: &Position, delta: usize) -> Position {
16+
if pre_insert_path.len() > b.len() {
17+
return b.clone();
18+
}
19+
if pre_insert_path.is_empty() || b.is_empty() {
20+
return b.clone();
21+
}
22+
// check the prefix
23+
for i in 0..(pre_insert_path.len()) {
24+
if pre_insert_path.0[i] != b.0[i] {
25+
return b.clone();
26+
}
27+
}
28+
let mut prefix: Vec<usize> = pre_insert_path.0[0..(pre_insert_path.len() - 1)].into();
29+
let mut suffix: Vec<usize> = b.0[pre_insert_path.0.len()..].into();
30+
let prev_insert_last: usize = *pre_insert_path.0.last().unwrap();
31+
let b_at_index = b.0[pre_insert_path.0.len() - 1];
32+
if prev_insert_last <= b_at_index {
33+
prefix.push(b_at_index + delta);
34+
} else {
35+
prefix.push(b_at_index);
36+
}
37+
prefix.append(&mut suffix);
38+
return Position(prefix);
39+
}
840
}
941

1042
impl From<Vec<usize>> for Position {

shared-lib/lib-ot/src/core/document/transaction.rs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
1-
use std::collections::HashMap;
21
use crate::core::document::position::Position;
3-
use crate::core::{DeleteOperation, DocumentOperation, DocumentTree, InsertOperation, NodeAttributes, NodeData, UpdateOperation};
2+
use crate::core::{
3+
DeleteOperation, DocumentOperation, DocumentTree, InsertOperation, NodeAttributes, NodeData, UpdateOperation,
4+
};
5+
use std::collections::HashMap;
46

57
pub struct Transaction {
68
pub operations: Vec<DocumentOperation>,

shared-lib/lib-ot/tests/main.rs

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
use std::collections::HashMap;
21
use lib_ot::core::{DocumentTree, NodeData, TransactionBuilder};
2+
use std::collections::HashMap;
33

44
#[test]
55
fn main() {
@@ -21,9 +21,10 @@ fn test_documents() {
2121
assert_eq!(node_data.node_type, "text");
2222

2323
let mut tb = TransactionBuilder::new(&document);
24-
tb.update_attributes(&vec![0].into(), HashMap::from([
25-
("subtype".into(), Some("bullet-list".into())),
26-
]));
24+
tb.update_attributes(
25+
&vec![0].into(),
26+
HashMap::from([("subtype".into(), Some("bullet-list".into()))]),
27+
);
2728
let transaction = tb.finalize();
2829
document.apply(transaction);
2930

0 commit comments

Comments
 (0)