From 492df51e70e974d3e6ca8bfd0f26782da660fd2d Mon Sep 17 00:00:00 2001 From: AnotherTest Date: Mon, 8 Jun 2020 00:31:33 +0430 Subject: [PATCH] LibLine: Correctly handle line content overflow when on last line Fixes #2525 --- Libraries/LibLine/Editor.cpp | 13 ++++++++++++- Libraries/LibLine/Editor.h | 2 +- 2 files changed, 13 insertions(+), 2 deletions(-) diff --git a/Libraries/LibLine/Editor.cpp b/Libraries/LibLine/Editor.cpp index e67d212294..f8600758db 100644 --- a/Libraries/LibLine/Editor.cpp +++ b/Libraries/LibLine/Editor.cpp @@ -556,7 +556,7 @@ void Editor::handle_read_event() ctrl_held = false; continue; default: - dbgprintf("Shell: Unhandled final: %02x (%c)\r\n", codepoint, codepoint); + dbgprintf("LibLine: Unhandled final: %02x (%c)\r\n", codepoint, codepoint); m_state = InputState::Free; ctrl_held = false; continue; @@ -984,6 +984,7 @@ void Editor::refresh_display() swap(previous_num_columns, m_num_columns); has_cleaned_up = true; } + m_was_resized = false; } // Do not call hook on pure cursor movement. if (m_cached_prompt_valid && !m_refresh_needed && m_pending_chars.size() == 0) { @@ -992,6 +993,16 @@ void Editor::refresh_display() m_cached_buffer_size = m_buffer.size(); return; } + // We might be at the last line, and have more than one line; + // Refreshing the display will cause the terminal to scroll, + // so note that fact and bring origin up. + auto current_num_lines = num_lines(); + if (m_origin_row + current_num_lines > m_num_lines + 1) { + if (current_num_lines > m_num_lines) + m_origin_row = 0; + else + m_origin_row = m_num_lines - current_num_lines + 1; + } if (on_display_refresh) on_display_refresh(*this); diff --git a/Libraries/LibLine/Editor.h b/Libraries/LibLine/Editor.h index c6846d851e..29bdf381ab 100644 --- a/Libraries/LibLine/Editor.h +++ b/Libraries/LibLine/Editor.h @@ -250,7 +250,7 @@ private: size_t cursor_line() const { - return (m_drawn_cursor + m_num_columns + current_prompt_length() - 1) / m_num_columns; + return (m_drawn_cursor + m_num_columns + current_prompt_length()) / m_num_columns; } size_t offset_in_line() const