11use crate :: core:: document:: position:: Position ;
22use crate :: core:: { DocumentOperation , DocumentTree , NodeAttributes , NodeSubTree } ;
33use std:: collections:: HashMap ;
4+ use indextree:: NodeId ;
45
56pub struct Transaction {
67 pub operations : Vec < DocumentOperation > ,
@@ -62,14 +63,7 @@ impl<'a> TransactionBuilder<'a> {
6263 let mut deleted_nodes: Vec < Box < NodeSubTree > > = Vec :: new ( ) ;
6364
6465 for _ in 0 ..length {
65- let node_data = self . document . arena . get ( node) . unwrap ( ) ;
66- let data = node_data. get ( ) ;
67- deleted_nodes. push ( Box :: new ( NodeSubTree {
68- node_type : data. node_type . clone ( ) ,
69- attributes : data. attributes . clone ( ) ,
70- delta : data. delta . clone ( ) ,
71- children : vec ! [ ] ,
72- } ) ) ;
66+ deleted_nodes. push ( self . get_deleted_nodes ( node. clone ( ) ) ) ;
7367 node = node. following_siblings ( & self . document . arena ) . next ( ) . unwrap ( ) ;
7468 }
7569
@@ -79,6 +73,29 @@ impl<'a> TransactionBuilder<'a> {
7973 } )
8074 }
8175
76+ fn get_deleted_nodes ( & self , node_id : NodeId ) -> Box < NodeSubTree > {
77+ let node = self . document . arena . get ( node_id. clone ( ) ) . unwrap ( ) ;
78+ let node_data = node. get ( ) ;
79+ let mut children: Vec < Box < NodeSubTree > > = vec ! [ ] ;
80+
81+ let mut children_iterators = node_id. children ( & self . document . arena ) ;
82+ loop {
83+ let next_child = children_iterators. next ( ) ;
84+ if let Some ( child_id) = next_child {
85+ children. push ( self . get_deleted_nodes ( child_id) ) ;
86+ } else {
87+ break ;
88+ }
89+ } ;
90+
91+ Box :: new ( NodeSubTree {
92+ node_type : node_data. node_type . clone ( ) ,
93+ attributes : node_data. attributes . clone ( ) ,
94+ delta : node_data. delta . clone ( ) ,
95+ children,
96+ } )
97+ }
98+
8299 pub fn push ( & mut self , op : DocumentOperation ) {
83100 self . operations . push ( op) ;
84101 }
0 commit comments