Skip to content

Commit eefb363

Browse files
committed
Fix chunk#fragments
1 parent cdb9719 commit eefb363

File tree

1 file changed

+13
-5
lines changed

1 file changed

+13
-5
lines changed

src/chunk.rs

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
use std::{collections::VecDeque, borrow::Cow};
1+
use std::{borrow::Cow, collections::VecDeque};
22

33
use crate::{span::Span, ChunkIdx, CowStr};
44

@@ -49,19 +49,28 @@ impl<'str> Chunk<'str> {
4949
self.intro.push_front(content)
5050
}
5151

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> {
5353
let first_slice_span = Span(self.start(), text_index);
5454
let last_slice_span = Span(text_index, self.end());
5555
let mut new_chunk = Chunk::new(last_slice_span);
56+
if self.is_edited() {
57+
new_chunk.edit("".into())
58+
}
5659
std::mem::swap(&mut new_chunk.outro, &mut self.outro);
5760
self.span = first_slice_span;
5861
new_chunk.next = self.next;
5962
new_chunk
6063
}
6164

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> {
6369
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()));
6574
let outro_iter = self.outro.iter().map(|frag| frag.as_ref());
6675
intro_iter.chain(Some(source_frag)).chain(outro_iter)
6776
}
@@ -74,4 +83,3 @@ impl<'str> Chunk<'str> {
7483
self.content.is_some()
7584
}
7685
}
77-

0 commit comments

Comments
 (0)