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
This commit is contained in:
AnotherTest 2020-04-10 09:35:53 +04:30 committed by Andreas Kling
parent 870936085a
commit 1b422315fa
Notes: sideshowbarker 2024-07-19 07:45:29 +09:00

View file

@ -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