1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-27 02:07:36 +00:00

Terminal: Try to preserve line contents when resizing the terminal window.

This is still destructive when shrinking, but clearly better than throwing
everything away.
This commit is contained in:
Andreas Kling 2019-07-08 19:01:02 +02:00
parent 4d904340b4
commit 2c81477f16
2 changed files with 12 additions and 8 deletions

View file

@ -87,6 +87,10 @@ void Terminal::Line::set_length(u16 new_length)
auto* new_characters = new u8[new_length];
auto* new_attributes = new Attribute[new_length];
memset(new_characters, ' ', new_length);
if (characters && attributes) {
memcpy(new_characters, characters, min(m_length, new_length));
memcpy(new_attributes, attributes, min(m_length, new_length) * sizeof(Attribute));
}
delete[] characters;
delete[] attributes;
characters = new_characters;
@ -938,10 +942,10 @@ void Terminal::set_size(u16 columns, u16 rows)
m_scroll_region_top = 0;
m_scroll_region_bottom = rows - 1;
m_cursor_row = 0;
m_cursor_column = 0;
m_saved_cursor_row = 0;
m_saved_cursor_column = 0;
m_cursor_row = min((int)m_cursor_row, m_rows - 1);
m_cursor_column = min((int)m_cursor_column, m_columns - 1);
m_saved_cursor_row = min((int)m_saved_cursor_row, m_rows - 1);
m_saved_cursor_column = min((int)m_saved_cursor_column, m_columns - 1);
m_horizontal_tabs.resize(columns);
for (unsigned i = 0; i < columns; ++i)