@@ -136,11 +136,16 @@ impl DocStore {
136
136
}
137
137
}
138
138
139
- pub fn get_item < I : Into < Id > > ( & self , id : I ) -> Option < StructInfo > {
140
- self . get_item_with_idx ( id) . map ( |( item, _) | item)
139
+ pub fn get_item < I : Into < Id > > ( & self , id : I ) -> Option < Arc < Item > > {
140
+ self . get_node_with_idx ( id)
141
+ . and_then ( |( item, _) | item. as_item ( ) )
141
142
}
142
143
143
- pub fn get_item_with_idx < I : Into < Id > > ( & self , id : I ) -> Option < ( StructInfo , usize ) > {
144
+ pub fn get_node < I : Into < Id > > ( & self , id : I ) -> Option < StructInfo > {
145
+ self . get_node_with_idx ( id) . map ( |( item, _) | item)
146
+ }
147
+
148
+ pub fn get_node_with_idx < I : Into < Id > > ( & self , id : I ) -> Option < ( StructInfo , usize ) > {
144
149
let id = id. into ( ) ;
145
150
if let Some ( items) = self . items . read ( ) . unwrap ( ) . get ( & id. client ) {
146
151
if let Some ( index) = Self :: get_item_index ( items, id. clock ) {
@@ -151,7 +156,7 @@ impl DocStore {
151
156
None
152
157
}
153
158
154
- pub fn split_item < I : Into < Id > > (
159
+ pub fn split_node < I : Into < Id > > (
155
160
& mut self ,
156
161
id : I ,
157
162
diff : u64 ,
@@ -295,7 +300,7 @@ impl DocStore {
295
300
let mut o = s. clone ( ) ;
296
301
297
302
while let Some ( left_id) = o. left_id ( ) {
298
- if let Some ( left_struct) = self . get_item ( left_id) {
303
+ if let Some ( left_struct) = self . get_node ( left_id) {
299
304
if left_struct. is_item ( ) {
300
305
o = left_struct;
301
306
} else {
@@ -334,7 +339,7 @@ impl DocStore {
334
339
// Item { id: (1, 0), content: Content::Type(YText) }
335
340
// ^^ Parent::Id((1, 0))
336
341
Some ( Parent :: Id ( parent_id) ) => {
337
- match self . get_item ( * parent_id) {
342
+ match self . get_node ( * parent_id) {
338
343
Some ( StructInfo :: Item ( _) ) => match & item. content . as_ref ( ) {
339
344
Content :: Type ( ty) => {
340
345
item. parent . replace ( Parent :: Type ( ty. clone ( ) ) ) ;
@@ -355,11 +360,11 @@ impl DocStore {
355
360
}
356
361
// no item.parent, borrow left.parent or right.parent
357
362
None => {
358
- if let Some ( left) = item. left_id . and_then ( |left_id| self . get_item ( left_id) ) {
363
+ if let Some ( left) = item. left_id . and_then ( |left_id| self . get_node ( left_id) ) {
359
364
item. parent = left. parent ( ) . cloned ( ) ;
360
365
item. parent_sub = left. parent_sub ( ) . cloned ( ) ;
361
366
} else if let Some ( right) =
362
- item. right_id . and_then ( |right_id| self . get_item ( right_id) )
367
+ item. right_id . and_then ( |right_id| self . get_node ( right_id) )
363
368
{
364
369
item. parent = right. parent ( ) . cloned ( ) ;
365
370
item. parent_sub = right. parent_sub ( ) . cloned ( ) ;
@@ -405,8 +410,8 @@ impl DocStore {
405
410
parent_lock. as_deref_mut ( ) . unwrap ( )
406
411
} ;
407
412
408
- let mut left = item. left_id . and_then ( |left_id| self . get_item ( left_id) ) ;
409
- let mut right = item. right_id . and_then ( |right_id| self . get_item ( right_id) ) ;
413
+ let mut left = item. left_id . and_then ( |left_id| self . get_node ( left_id) ) ;
414
+ let mut right = item. right_id . and_then ( |right_id| self . get_node ( right_id) ) ;
410
415
411
416
let right_is_null_or_has_left = match & right {
412
417
None => true ,
@@ -423,7 +428,7 @@ impl DocStore {
423
428
{
424
429
// set the first conflicting item
425
430
let mut o = if let Some ( left) = left. clone ( ) {
426
- left. right_id ( ) . and_then ( |right_id| self . get_item ( right_id) )
431
+ left. right_id ( ) . and_then ( |right_id| self . get_node ( right_id) )
427
432
} else if let Some ( parent_sub) = & item. parent_sub {
428
433
let o = parent. map . as_ref ( ) . and_then ( |m| m. get ( parent_sub) . cloned ( ) ) ;
429
434
o. as_ref ( ) . map ( |o| self . get_start_item ( o) )
@@ -466,7 +471,7 @@ impl DocStore {
466
471
break ;
467
472
}
468
473
o = match c. right_id {
469
- Some ( right_id) => self . get_item ( right_id) ,
474
+ Some ( right_id) => self . get_node ( right_id) ,
470
475
None => None ,
471
476
} ;
472
477
}
@@ -894,7 +899,7 @@ mod tests {
894
899
} ;
895
900
doc_store. add_item ( struct_info. clone ( ) ) . unwrap ( ) ;
896
901
897
- assert_eq ! ( doc_store. get_item ( Id :: new( 1 , 9 ) ) , Some ( struct_info) ) ;
902
+ assert_eq ! ( doc_store. get_node ( Id :: new( 1 , 9 ) ) , Some ( struct_info) ) ;
898
903
}
899
904
900
905
{
@@ -910,13 +915,13 @@ mod tests {
910
915
doc_store. add_item ( struct_info1) . unwrap ( ) ;
911
916
doc_store. add_item ( struct_info2. clone ( ) ) . unwrap ( ) ;
912
917
913
- assert_eq ! ( doc_store. get_item ( Id :: new( 1 , 25 ) ) , Some ( struct_info2) ) ;
918
+ assert_eq ! ( doc_store. get_node ( Id :: new( 1 , 25 ) ) , Some ( struct_info2) ) ;
914
919
}
915
920
916
921
{
917
922
let doc_store = DocStore :: new ( ) ;
918
923
919
- assert_eq ! ( doc_store. get_item ( Id :: new( 1 , 0 ) ) , None ) ;
924
+ assert_eq ! ( doc_store. get_node ( Id :: new( 1 , 0 ) ) , None ) ;
920
925
}
921
926
922
927
{
@@ -932,7 +937,7 @@ mod tests {
932
937
doc_store. add_item ( struct_info1) . unwrap ( ) ;
933
938
doc_store. add_item ( struct_info2) . unwrap ( ) ;
934
939
935
- assert_eq ! ( doc_store. get_item ( Id :: new( 1 , 35 ) ) , None ) ;
940
+ assert_eq ! ( doc_store. get_node ( Id :: new( 1 , 35 ) ) , None ) ;
936
941
}
937
942
}
938
943
@@ -956,7 +961,7 @@ mod tests {
956
961
doc_store. add_item ( struct_info1. clone ( ) ) . unwrap ( ) ;
957
962
doc_store. add_item ( struct_info2) . unwrap ( ) ;
958
963
959
- let s1 = doc_store. get_item ( Id :: new ( 1 , 0 ) ) . unwrap ( ) ;
964
+ let s1 = doc_store. get_node ( Id :: new ( 1 , 0 ) ) . unwrap ( ) ;
960
965
assert_eq ! ( s1, struct_info1) ;
961
966
let left = doc_store. split_at_and_get_left ( ( 1 , 1 ) ) . unwrap ( ) ;
962
967
assert_eq ! ( left. len( ) , 2 ) ; // octo => oc_to
0 commit comments