Skip to content

Commit 61d181b

Browse files
committed
feat: vec to position convertion
1 parent 8401fa0 commit 61d181b

File tree

2 files changed

+17
-5
lines changed

2 files changed

+17
-5
lines changed

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

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,3 +6,9 @@ impl Position {
66
self.0.is_empty()
77
}
88
}
9+
10+
impl From<Vec<usize>> for Position {
11+
fn from(v: Vec<usize>) -> Self {
12+
Position(v)
13+
}
14+
}

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

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

44
#[test]
55
fn main() {
@@ -11,19 +11,25 @@ fn main() {
1111
fn test_documents() {
1212
let mut document = DocumentTree::new();
1313
let mut tb = TransactionBuilder::new(&document);
14-
tb.insert_nodes(&Position(vec![0]), &vec![NodeData::new("text")]);
14+
tb.insert_nodes(&vec![0].into(), &vec![NodeData::new("text")]);
1515
let transaction = tb.finalize();
1616
document.apply(transaction);
1717

18-
assert!(document.node_at_path(&Position(vec![0])).is_some());
19-
let node = document.node_at_path(&Position(vec![0])).unwrap();
18+
assert!(document.node_at_path(&vec![0].into()).is_some());
19+
let node = document.node_at_path(&vec![0].into()).unwrap();
2020
let node_data = document.arena.get(node).unwrap().get();
2121
assert_eq!(node_data.node_type, "text");
2222

2323
let mut tb = TransactionBuilder::new(&document);
24-
tb.update_attributes(&Position(vec![0]), HashMap::from([
24+
tb.update_attributes(&vec![0].into(), HashMap::from([
2525
("subtype".into(), Some("bullet-list".into())),
2626
]));
2727
let transaction = tb.finalize();
2828
document.apply(transaction);
29+
30+
let mut tb = TransactionBuilder::new(&document);
31+
tb.delete_node(&vec![0].into());
32+
let transaction = tb.finalize();
33+
document.apply(transaction);
34+
assert!(document.node_at_path(&vec![0].into()).is_none());
2935
}

0 commit comments

Comments
 (0)