mirror of
https://github.com/AppFlowy-IO/AppFlowy.git
synced 2024-08-30 18:12:39 +00:00
feat: vec to position convertion
This commit is contained in:
parent
8401fa0983
commit
61d181b228
@ -6,3 +6,9 @@ impl Position {
|
||||
self.0.is_empty()
|
||||
}
|
||||
}
|
||||
|
||||
impl From<Vec<usize>> for Position {
|
||||
fn from(v: Vec<usize>) -> Self {
|
||||
Position(v)
|
||||
}
|
||||
}
|
||||
|
@ -1,5 +1,5 @@
|
||||
use std::collections::HashMap;
|
||||
use lib_ot::core::{DocumentTree, NodeData, Position, TransactionBuilder};
|
||||
use lib_ot::core::{DocumentTree, NodeData, TransactionBuilder};
|
||||
|
||||
#[test]
|
||||
fn main() {
|
||||
@ -11,19 +11,25 @@ fn main() {
|
||||
fn test_documents() {
|
||||
let mut document = DocumentTree::new();
|
||||
let mut tb = TransactionBuilder::new(&document);
|
||||
tb.insert_nodes(&Position(vec![0]), &vec![NodeData::new("text")]);
|
||||
tb.insert_nodes(&vec![0].into(), &vec![NodeData::new("text")]);
|
||||
let transaction = tb.finalize();
|
||||
document.apply(transaction);
|
||||
|
||||
assert!(document.node_at_path(&Position(vec![0])).is_some());
|
||||
let node = document.node_at_path(&Position(vec![0])).unwrap();
|
||||
assert!(document.node_at_path(&vec![0].into()).is_some());
|
||||
let node = document.node_at_path(&vec![0].into()).unwrap();
|
||||
let node_data = document.arena.get(node).unwrap().get();
|
||||
assert_eq!(node_data.node_type, "text");
|
||||
|
||||
let mut tb = TransactionBuilder::new(&document);
|
||||
tb.update_attributes(&Position(vec![0]), HashMap::from([
|
||||
tb.update_attributes(&vec![0].into(), HashMap::from([
|
||||
("subtype".into(), Some("bullet-list".into())),
|
||||
]));
|
||||
let transaction = tb.finalize();
|
||||
document.apply(transaction);
|
||||
|
||||
let mut tb = TransactionBuilder::new(&document);
|
||||
tb.delete_node(&vec![0].into());
|
||||
let transaction = tb.finalize();
|
||||
document.apply(transaction);
|
||||
assert!(document.node_at_path(&vec![0].into()).is_none());
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user