mirror of
https://github.com/wez/wezterm.git
synced 2024-12-28 07:55:03 +03:00
join lines with CRLF when fully repainting surface
When repainting a surface, we optimize for the case where lines are simple text by combining the the `Change::Text` for the end of the previous line and the start of the next line into a single `Change`. The assumption about relying on automatic margins is incorrect. We can't rely on them, as they might be disabled, and in any case they are no use if the previous line was shorter than the full width of the screen. This results in the lines appearing joined together on a single line. This is evidenced in the existing tests where `"hel\nw"` becomes `"helw"` on a full repaint. The solution is to always inject a real CRLF by adding a `CursorPosition` change. This replaces any CRLF that may have been swallowed by the `Surface` when it added the original changes.
This commit is contained in:
parent
5d7abfb86a
commit
111f42cf7b
@ -614,16 +614,7 @@ impl Surface {
|
||||
|
||||
let mut changes = line.changes(&attr);
|
||||
|
||||
let result_len = result.len();
|
||||
if !changes.is_empty() && result[result_len - 1].is_text() && changes[0].is_text() {
|
||||
// Assumption: that the output has working automatic margins.
|
||||
// We can skip the cursor position change and just join the
|
||||
// text items together
|
||||
if let Change::Text(mut prefix) = result.remove(result_len - 1) {
|
||||
prefix.push_str(changes[0].text());
|
||||
changes[0] = Change::Text(prefix);
|
||||
}
|
||||
} else if idx != 0 {
|
||||
if idx != 0 {
|
||||
// We emit a relative move at the end of each
|
||||
// line with the theory that this will translate
|
||||
// to a short \r\n sequence rather than the longer
|
||||
@ -913,7 +904,12 @@ mod test {
|
||||
assert_eq!(
|
||||
&[
|
||||
Change::ClearScreen(Default::default()),
|
||||
Change::Text("helw".into()),
|
||||
Change::Text("hel".into()),
|
||||
Change::CursorPosition {
|
||||
x: Position::Absolute(0),
|
||||
y: Position::Relative(1),
|
||||
},
|
||||
Change::Text("w".into()),
|
||||
Change::CursorPosition {
|
||||
x: Position::Absolute(1),
|
||||
y: Position::Absolute(1),
|
||||
@ -945,7 +941,12 @@ mod test {
|
||||
.set_background(AnsiColor::Red)
|
||||
.clone()
|
||||
),
|
||||
Change::Text("helw".into()),
|
||||
Change::Text("hel".into()),
|
||||
Change::CursorPosition {
|
||||
x: Position::Absolute(0),
|
||||
y: Position::Relative(1),
|
||||
},
|
||||
Change::Text("w".into()),
|
||||
Change::ClearToEndOfScreen(AnsiColor::Red.into()),
|
||||
Change::CursorPosition {
|
||||
x: Position::Absolute(1),
|
||||
|
Loading…
Reference in New Issue
Block a user