1
- use std:: { collections :: VecDeque , borrow :: Cow } ;
1
+ use std:: { borrow :: Cow , collections :: VecDeque } ;
2
2
3
3
use crate :: { span:: Span , ChunkIdx , CowStr } ;
4
4
@@ -49,19 +49,28 @@ impl<'str> Chunk<'str> {
49
49
self . intro . push_front ( content)
50
50
}
51
51
52
- pub fn split < ' a , > ( & ' a mut self , text_index : u32 ) -> Chunk < ' str > {
52
+ pub fn split < ' a > ( & ' a mut self , text_index : u32 ) -> Chunk < ' str > {
53
53
let first_slice_span = Span ( self . start ( ) , text_index) ;
54
54
let last_slice_span = Span ( text_index, self . end ( ) ) ;
55
55
let mut new_chunk = Chunk :: new ( last_slice_span) ;
56
+ if self . is_edited ( ) {
57
+ new_chunk. edit ( "" . into ( ) )
58
+ }
56
59
std:: mem:: swap ( & mut new_chunk. outro , & mut self . outro ) ;
57
60
self . span = first_slice_span;
58
61
new_chunk. next = self . next ;
59
62
new_chunk
60
63
}
61
64
62
- pub fn fragments ( & ' str self , original_source : & ' str CowStr < ' str > ) -> impl Iterator < Item = & ' str str > {
65
+ pub fn fragments (
66
+ & ' str self ,
67
+ original_source : & ' str CowStr < ' str > ,
68
+ ) -> impl Iterator < Item = & ' str str > {
63
69
let intro_iter = self . intro . iter ( ) . map ( |frag| frag. as_ref ( ) ) ;
64
- let source_frag = self . content . as_deref ( ) . unwrap_or_else ( || self . span . text ( original_source. as_ref ( ) ) ) ;
70
+ let source_frag = self
71
+ . content
72
+ . as_deref ( )
73
+ . unwrap_or_else ( || self . span . text ( original_source. as_ref ( ) ) ) ;
65
74
let outro_iter = self . outro . iter ( ) . map ( |frag| frag. as_ref ( ) ) ;
66
75
intro_iter. chain ( Some ( source_frag) ) . chain ( outro_iter)
67
76
}
@@ -74,4 +83,3 @@ impl<'str> Chunk<'str> {
74
83
self . content . is_some ( )
75
84
}
76
85
}
77
-
0 commit comments