mirror of
https://github.com/RGBCube/serenity
synced 2025-07-26 00:57:36 +00:00
LibLine: Properly handle window resize by not spamming DSRs
We have all the information necessary to find our new origin when a window size change occurs.
This commit is contained in:
parent
173c65660a
commit
f946d6ce79
2 changed files with 18 additions and 1 deletions
|
@ -407,6 +407,22 @@ String Editor::get_line(const String& prompt)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void Editor::recalculate_origin()
|
||||||
|
{
|
||||||
|
// changing the columns can affect our origin if
|
||||||
|
// the new size is smaller than our prompt, which would
|
||||||
|
// cause said prompt to take up more space, so we should
|
||||||
|
// compensate for that
|
||||||
|
if (m_cached_prompt_length >= m_num_columns) {
|
||||||
|
auto added_lines = (m_cached_prompt_length + 1) / m_num_columns - 1;
|
||||||
|
dbg() << "added lines: " << added_lines;
|
||||||
|
m_origin_x += added_lines;
|
||||||
|
}
|
||||||
|
|
||||||
|
// we also need to recalculate our cursor position
|
||||||
|
// but that will be calculated and applied at the next
|
||||||
|
// refresh cycle
|
||||||
|
}
|
||||||
void Editor::refresh_display()
|
void Editor::refresh_display()
|
||||||
{
|
{
|
||||||
auto cleanup = [&] {
|
auto cleanup = [&] {
|
||||||
|
@ -436,8 +452,8 @@ void Editor::refresh_display()
|
||||||
m_cached_prompt_valid = false;
|
m_cached_prompt_valid = false;
|
||||||
m_refresh_needed = true;
|
m_refresh_needed = true;
|
||||||
swap(previous_num_columns, m_num_columns);
|
swap(previous_num_columns, m_num_columns);
|
||||||
|
recalculate_origin();
|
||||||
cleanup();
|
cleanup();
|
||||||
set_origin();
|
|
||||||
swap(previous_num_columns, m_num_columns);
|
swap(previous_num_columns, m_num_columns);
|
||||||
has_cleaned_up = true;
|
has_cleaned_up = true;
|
||||||
}
|
}
|
||||||
|
|
|
@ -168,6 +168,7 @@ private:
|
||||||
m_origin_x = position[0];
|
m_origin_x = position[0];
|
||||||
m_origin_y = position[1];
|
m_origin_y = position[1];
|
||||||
}
|
}
|
||||||
|
void recalculate_origin();
|
||||||
void reposition_cursor();
|
void reposition_cursor();
|
||||||
|
|
||||||
Vector<char, 1024> m_buffer;
|
Vector<char, 1024> m_buffer;
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue