Replace \r and \r\n with \n when indexing text into the rope
This commit is contained in:
parent
582185b8cb
commit
f9bad2d81d
1 changed files with 9 additions and 1 deletions
|
@ -58,11 +58,19 @@ impl Rope {
|
||||||
pub fn push(&mut self, text: &str) {
|
pub fn push(&mut self, text: &str) {
|
||||||
let mut new_chunks = SmallVec::<[_; 16]>::new();
|
let mut new_chunks = SmallVec::<[_; 16]>::new();
|
||||||
let mut new_chunk = ArrayString::new();
|
let mut new_chunk = ArrayString::new();
|
||||||
for ch in text.chars() {
|
let mut chars = text.chars().peekable();
|
||||||
|
while let Some(mut ch) = chars.next() {
|
||||||
if new_chunk.len() + ch.len_utf8() > 2 * CHUNK_BASE {
|
if new_chunk.len() + ch.len_utf8() > 2 * CHUNK_BASE {
|
||||||
new_chunks.push(Chunk(new_chunk));
|
new_chunks.push(Chunk(new_chunk));
|
||||||
new_chunk = ArrayString::new();
|
new_chunk = ArrayString::new();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if ch == '\r' {
|
||||||
|
ch = '\n';
|
||||||
|
if chars.peek().copied() == Some('\n') {
|
||||||
|
chars.next();
|
||||||
|
}
|
||||||
|
}
|
||||||
new_chunk.push(ch);
|
new_chunk.push(ch);
|
||||||
}
|
}
|
||||||
if !new_chunk.is_empty() {
|
if !new_chunk.is_empty() {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue