Skip to content

Commit

Permalink
LibLine: Use the real shown line count around in cleanup()
Browse files Browse the repository at this point in the history
Previously we would leave artifacts on screen if a change caused the
buffer to span fewer lines than the current buffer.
This commit records the shown line count and uses that instead of trying
to guess the previous line count (and failing most of the time).
  • Loading branch information
alimpfard authored and awesomekling committed Jun 22, 2022
1 parent 92a1e96 commit 910a44d
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 3 deletions.
7 changes: 4 additions & 3 deletions Userland/Libraries/LibLine/Editor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1296,9 +1296,8 @@ void Editor::cleanup()
{
auto current_buffer_metrics = actual_rendered_string_metrics(buffer_view(), m_current_masks);
auto new_lines = current_prompt_metrics().lines_with_addition(current_buffer_metrics, m_num_columns);
auto shown_lines = num_lines();
if (new_lines < shown_lines)
m_extra_forward_lines = max(shown_lines - new_lines, m_extra_forward_lines);
if (new_lines < m_shown_lines)
m_extra_forward_lines = max(m_shown_lines - new_lines, m_extra_forward_lines);

OutputFileStream stderr_stream { stderr };
reposition_cursor(stderr_stream, true);
Expand All @@ -1313,6 +1312,8 @@ void Editor::refresh_display()
DuplexMemoryStream output_stream;
ScopeGuard flush_stream {
[&] {
m_shown_lines = current_prompt_metrics().lines_with_addition(m_cached_buffer_metrics, m_num_columns);

auto buffer = output_stream.copy_into_contiguous_buffer();
if (buffer.is_empty())
return;
Expand Down
1 change: 1 addition & 0 deletions Userland/Libraries/LibLine/Editor.h
Original file line number Diff line number Diff line change
Expand Up @@ -432,6 +432,7 @@ class Editor : public Core::Object {
size_t m_num_lines { 1 };
size_t m_previous_num_columns { 0 };
size_t m_extra_forward_lines { 0 };
size_t m_shown_lines { 0 };
StringMetrics m_cached_prompt_metrics;
StringMetrics m_old_prompt_metrics;
StringMetrics m_cached_buffer_metrics;
Expand Down

0 comments on commit 910a44d

Please sign in to comment.