summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAnotherTest <ali.mpfard@gmail.com>2020-04-10 09:35:53 +0430
committerAndreas Kling <kling@serenityos.org>2020-04-10 11:26:44 +0200
commit1b422315fae44e83065c6f0343d8cbda875e4faf (patch)
tree538642d1fb1a7dbc63ed6bc78a4bea9655f2dea8
parent870936085a597671072ec836ed85d67afc703951 (diff)
downloadserenity-1b422315fae44e83065c6f0343d8cbda875e4faf.zip
LibLine: Fix regression with moving around in history misplacing cursor
This commit fixes a regression where the prompt would not be cleared upon substitution of lines from the history
-rw-r--r--Libraries/LibLine/Editor.cpp22
1 files changed, 16 insertions, 6 deletions
diff --git a/Libraries/LibLine/Editor.cpp b/Libraries/LibLine/Editor.cpp
index da6bfd65e1..dd35a884bc 100644
--- a/Libraries/LibLine/Editor.cpp
+++ b/Libraries/LibLine/Editor.cpp
@@ -203,17 +203,27 @@ String Editor::get_line(const String& prompt)
case 'A': // up
if (m_history_cursor > 0)
--m_history_cursor;
- clear_line();
- if (m_history_cursor < m_history.size())
- insert(m_history[m_history_cursor]);
+ if (m_history_cursor < m_history.size()) {
+ auto& line = m_history[m_history_cursor];
+ m_buffer.clear();
+ for (auto& c : line)
+ m_buffer.append(c);
+ m_cursor = m_buffer.size();
+ m_refresh_needed = true;
+ }
m_state = InputState::Free;
continue;
case 'B': // down
if (m_history_cursor < m_history.size())
++m_history_cursor;
- clear_line();
- if (m_history_cursor < m_history.size())
- insert(m_history[m_history_cursor]);
+ if (m_history_cursor < m_history.size()) {
+ auto& line = m_history[m_history_cursor];
+ m_buffer.clear();
+ for (auto& c : line)
+ m_buffer.append(c);
+ m_cursor = m_buffer.size();
+ m_refresh_needed = true;
+ }
m_state = InputState::Free;
continue;
case 'D': // left