From 5d1425718e65ba166098b65c2cbc01758fa8f43f Mon Sep 17 00:00:00 2001 From: AnotherTest Date: Fri, 18 Dec 2020 15:29:07 +0330 Subject: [PATCH] LibLine: Treat leftover data in buffer as a read event Fixes #4328. --- Libraries/LibLine/Editor.cpp | 38 ++++++++++++++++++++++-------------- Libraries/LibLine/Editor.h | 1 + 2 files changed, 24 insertions(+), 15 deletions(-) diff --git a/Libraries/LibLine/Editor.cpp b/Libraries/LibLine/Editor.cpp index e72977b0ea8..6ad89695c7a 100644 --- a/Libraries/LibLine/Editor.cpp +++ b/Libraries/LibLine/Editor.cpp @@ -557,21 +557,9 @@ auto Editor::get_line(const String& prompt) -> Result m_notifier = Core::Notifier::construct(STDIN_FILENO, Core::Notifier::Read); add_child(*m_notifier); - m_notifier->on_ready_to_read = [&] { - if (m_was_interrupted) { - handle_interrupt_event(); - } - - handle_read_event(); - - if (m_always_refresh) - m_refresh_needed = true; - - refresh_display(); - - if (m_finish) - really_quit_event_loop(); - }; + m_notifier->on_ready_to_read = [&] { try_update_once(); }; + if (!m_incomplete_data.is_empty()) + deferred_invoke([&](auto&) { try_update_once(); }); if (loop.exec() == Retry) return get_line(prompt); @@ -597,6 +585,23 @@ void Editor::save_to(JsonObject& object) object.set("used_display_area", move(display_area)); } +void Editor::try_update_once() +{ + if (m_was_interrupted) { + handle_interrupt_event(); + } + + handle_read_event(); + + if (m_always_refresh) + m_refresh_needed = true; + + refresh_display(); + + if (m_finish) + really_quit_event_loop(); +} + void Editor::handle_interrupt_event() { m_was_interrupted = false; @@ -924,6 +929,9 @@ void Editor::handle_read_event() for (size_t i = 0; i < consumed_code_points; ++i) m_incomplete_data.take_first(); } + + if (!m_incomplete_data.is_empty() && !m_finish) + deferred_invoke([&](auto&) { try_update_once(); }); } void Editor::cleanup_suggestions() diff --git a/Libraries/LibLine/Editor.h b/Libraries/LibLine/Editor.h index f2513fbe6c3..b6f2ba510ef 100644 --- a/Libraries/LibLine/Editor.h +++ b/Libraries/LibLine/Editor.h @@ -262,6 +262,7 @@ private: // FIXME: Port to Core::Property void save_to(JsonObject&); + void try_update_once(); void handle_interrupt_event(); void handle_read_event();