From 910a44d5f29f66cd81f270f7beb6a348525265c3 Mon Sep 17 00:00:00 2001 From: Ali Mohammad Pur Date: Tue, 21 Jun 2022 18:40:36 +0430 Subject: [PATCH] LibLine: Use the real shown line count around in cleanup() 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). --- Userland/Libraries/LibLine/Editor.cpp | 7 ++++--- Userland/Libraries/LibLine/Editor.h | 1 + 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/Userland/Libraries/LibLine/Editor.cpp b/Userland/Libraries/LibLine/Editor.cpp index 1396a3bd41..5c46e11346 100644 --- a/Userland/Libraries/LibLine/Editor.cpp +++ b/Userland/Libraries/LibLine/Editor.cpp @@ -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); @@ -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; diff --git a/Userland/Libraries/LibLine/Editor.h b/Userland/Libraries/LibLine/Editor.h index c081691460..0dbe064153 100644 --- a/Userland/Libraries/LibLine/Editor.h +++ b/Userland/Libraries/LibLine/Editor.h @@ -432,6 +432,7 @@ private: 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;