mirror of
https://github.com/loro-dev/loro.git
synced 2025-01-22 12:57:20 +00:00
fix: move child in current parent
This commit is contained in:
parent
2b7a621744
commit
bd9c2b25a8
2 changed files with 14 additions and 1 deletions
|
@ -538,7 +538,10 @@ impl TreeHandler {
|
|||
self.move_to(target, parent, index)
|
||||
}
|
||||
MaybeDetached::Attached(a) => {
|
||||
let index: usize = self.children_num(&parent).unwrap_or(0);
|
||||
let mut index: usize = self.children_num(&parent).unwrap_or(0);
|
||||
if self.is_parent(&target, &parent) {
|
||||
index -= 1;
|
||||
}
|
||||
a.with_txn(|txn| {
|
||||
self.mov_with_txn(txn, target, parent, index, FiIfNotConfigured::Zero)
|
||||
})
|
||||
|
|
|
@ -23,3 +23,13 @@ fn tree_index() {
|
|||
assert_eq!(tree.get_index_by_tree_id(&child).unwrap(), 1);
|
||||
assert_eq!(tree.get_index_by_tree_id(&child2).unwrap(), 0);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn tree_move_in_parent() {
|
||||
let doc = LoroDoc::new_auto_commit();
|
||||
doc.set_peer_id(0).unwrap();
|
||||
let tree = doc.get_tree("tree");
|
||||
let root = tree.create(TreeParentId::Root).unwrap();
|
||||
let child = tree.create(root.into()).unwrap();
|
||||
tree.mov(child, root.into()).unwrap();
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue