Fix pasting of multiline text via bracketed paste

Bracketed paste uses CR as its newline delimiter.
This commit is contained in:
Leonard Hecker
2025-04-03 18:09:22 +02:00
parent fa5a40c036
commit 87a3bbda6d

View File

@@ -1743,17 +1743,9 @@ impl TextBuffer {
let mut newline_buffer = String::new();
loop {
let (offset_next, _) = ucd::newlines_forward(text, offset, 0, 1);
let mut line = &text[offset..offset_next];
// Trim trailing LF or CRLF, if any.
if line.ends_with(b"\n") {
line = &line[..line.len() - 1]
}
if line.ends_with(b"\r") {
line = &line[..line.len() - 1]
}
// Can't use `ucd::newlines_forward` because bracketed paste uses CR instead of LF/CRLF.
let offset_next = memchr2(b'\r', b'\n', text, offset);
let line = &text[offset..offset_next];
let column_before = self.cursor.logical_pos.x;
// Write the contents of the line into the buffer.
@@ -1843,7 +1835,19 @@ impl TextBuffer {
self.edit_write(newline_buffer.as_bytes());
offset = offset_next;
// Skip one CR(LF).
if offset >= text.len() {
break;
}
if text[offset] == b'\r' {
offset += 1;
}
if offset >= text.len() {
break;
}
if text[offset] == b'\n' {
offset += 1;
}
if offset >= text.len() {
break;
}