fix(terminal): properly handle resizes in alternate screen (#2654)

This commit is contained in:
Aram Drevekenin 2023-07-27 17:55:21 +02:00 committed by GitHub
parent 5601766225
commit ade4406a8f
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 43 additions and 33 deletions

View file

@ -910,6 +910,12 @@ impl OutputBuffer {
if row_width < viewport_width {
let mut padding = vec![EMPTY_TERMINAL_CHARACTER; viewport_width - row_width];
terminal_characters.append(&mut padding);
} else if row_width > viewport_width {
let width_offset = row.excess_width_until(viewport_width);
let truncate_position = viewport_width.saturating_sub(width_offset);
if truncate_position < terminal_characters.len() {
terminal_characters.truncate(truncate_position);
}
}
terminal_characters
}

View file

@ -760,9 +760,16 @@ impl Grid {
if new_columns == 0 || new_rows == 0 {
return;
}
if self.alternate_screen_state.is_some() {
// in alternate screen we do nothing but log the new size, the program in the terminal
// is in control now...
self.height = new_rows;
self.width = new_columns;
return;
}
self.selection.reset();
self.sixel_grid.character_cell_size_possibly_changed();
if new_columns != self.width && self.alternate_screen_state.is_none() {
if new_columns != self.width {
self.horizontal_tabstops = create_horizontal_tabstops(new_columns);
let mut cursor_canonical_line_index = self.cursor_canonical_line_index();
let cursor_index_in_canonical_line = self.cursor_index_in_canonical_line();
@ -917,14 +924,6 @@ impl Grid {
},
}
};
} else if new_columns != self.width && self.alternate_screen_state.is_some() {
// in alternate screen just truncate exceeding width
for row in &mut self.viewport {
if row.width() >= new_columns {
let truncate_at = row.position_accounting_for_widechars(new_columns);
row.columns.truncate(truncate_at);
}
}
}
if new_rows != self.height {
let current_viewport_row_count = self.viewport.len();
@ -959,18 +958,13 @@ impl Grid {
.saturating_sub(row_count_to_transfer);
};
}
if self.alternate_screen_state.is_none() {
transfer_rows_from_viewport_to_lines_above(
&mut self.viewport,
&mut self.lines_above,
&mut self.sixel_grid,
row_count_to_transfer,
new_columns,
);
} else {
// in alternate screen, no scroll buffer, so just remove lines
self.viewport.drain(0..row_count_to_transfer);
}
transfer_rows_from_viewport_to_lines_above(
&mut self.viewport,
&mut self.lines_above,
&mut self.sixel_grid,
row_count_to_transfer,
new_columns,
);
},
Ordering::Equal => {},
}
@ -1340,7 +1334,7 @@ impl Grid {
if character_width == 0 {
return;
}
if self.cursor.x + character_width > self.width {
if self.cursor.x + character_width > self.width && self.alternate_screen_state.is_none() {
if self.disable_linewrap {
return;
}

View file

@ -1,16 +1,26 @@
---
source: zellij-server/src/panes/./unit/grid_tests.rs
assertion_line: 2137
expression: "format!(\"{:?}\", grid)"
---
00 (C): line12aaaa
01 (C): line13aaaa
02 (C): line14aaaa
03 (C): line15aaaa
04 (C): line16aaaa
05 (C): line17aaaa
06 (C): line18aaaa
07 (C): line19a🦀a
08 (C): line20a🦀
09 (C): line21🦀🦀
00 (C): line2aaaaaaaaaaaaaaa
01 (C): line3aaaaaaaaaaaaaaa
02 (C): line4aaaaaaaaaaaaaaa
03 (C): line5aaaaaaaaaaaaaaa
04 (C): line6aaaaaaaaaaaaaaa
05 (C): line7aaaaaaaaaaaaaaa
06 (C): line8aaaaaaaaaaaaaaa
07 (C): line9aaaaaaaaaaaaaaa
08 (C): line10aaaaaaaaaaaaaa
09 (C): line11aaaaaaaaaaaaaa
10 (C): line12aaaaaaaaaaaaaa
11 (C): line13aaaaaaaaaaaaaa
12 (C): line14aaaaaaaaaaaaaa
13 (C): line15aaaaaaaaaaaaaa
14 (C): line16aaaaaaaaaaaaaa
15 (C): line17aaaaaaaaaaaaaa
16 (C): line18aaaaaaaaaaaaaa
17 (C): line19a🦀aaaaaaaaaaa
18 (C): line20a🦀🦀aaaaaaaaa
19 (C): line21🦀🦀🦀🦀🦀🦀🦀