diff options
author | AnotherTest <ali.mpfard@gmail.com> | 2021-02-07 03:12:17 +0330 |
---|---|---|
committer | Andreas Kling <kling@serenityos.org> | 2021-02-07 13:12:56 +0100 |
commit | 3a231c00aa80fe1e2ff38771874cb6b680558308 (patch) | |
tree | 666aaaff12ea157f2059d71ef78b26715f5f039b | |
parent | 5204c9062c5e2fd6448ce7da7ed6a223cfe77b23 (diff) | |
download | serenity-3a231c00aa80fe1e2ff38771874cb6b680558308.zip |
LibLine: Close the search editor when it's interrupted
Fixes #5233.
-rw-r--r-- | Userland/Libraries/LibLine/Editor.cpp | 5 | ||||
-rw-r--r-- | Userland/Libraries/LibLine/Editor.h | 1 | ||||
-rw-r--r-- | Userland/Libraries/LibLine/InternalFunctions.cpp | 8 |
3 files changed, 13 insertions, 1 deletions
diff --git a/Userland/Libraries/LibLine/Editor.cpp b/Userland/Libraries/LibLine/Editor.cpp index 2bba9c740f..326b5d079b 100644 --- a/Userland/Libraries/LibLine/Editor.cpp +++ b/Userland/Libraries/LibLine/Editor.cpp @@ -539,7 +539,7 @@ void Editor::interrupted() m_was_interrupted = true; handle_interrupt_event(); - if (!m_finish) + if (!m_finish || !m_previous_interrupt_was_handled_as_interrupt) return; m_finish = false; @@ -681,11 +681,14 @@ void Editor::try_update_once() void Editor::handle_interrupt_event() { m_was_interrupted = false; + m_previous_interrupt_was_handled_as_interrupt = false; m_callback_machine.interrupted(*this); if (!m_callback_machine.should_process_last_pressed_key()) return; + m_previous_interrupt_was_handled_as_interrupt = true; + fprintf(stderr, "^C"); fflush(stderr); diff --git a/Userland/Libraries/LibLine/Editor.h b/Userland/Libraries/LibLine/Editor.h index 407b3fd9fa..c6ebc9a005 100644 --- a/Userland/Libraries/LibLine/Editor.h +++ b/Userland/Libraries/LibLine/Editor.h @@ -448,6 +448,7 @@ private: struct termios m_default_termios { }; bool m_was_interrupted { false }; + bool m_previous_interrupt_was_handled_as_interrupt { true }; bool m_was_resized { false }; // FIXME: This should be something more take_first()-friendly. diff --git a/Userland/Libraries/LibLine/InternalFunctions.cpp b/Userland/Libraries/LibLine/InternalFunctions.cpp index 87a7d03b55..b031e3a396 100644 --- a/Userland/Libraries/LibLine/InternalFunctions.cpp +++ b/Userland/Libraries/LibLine/InternalFunctions.cpp @@ -258,6 +258,14 @@ void Editor::enter_search() return false; // Do not process this key event }); + // ^C should cancel the search. + m_search_editor->register_key_input_callback(ctrl('C'), [this](Editor& search_editor) { + search_editor.finish(); + m_reset_buffer_on_search_end = true; + search_editor.deferred_invoke([&search_editor](auto&) { search_editor.really_quit_event_loop(); }); + return false; + }); + // Whenever the search editor gets a backspace, cycle back between history entries // unless we're at the zeroth entry, in which case, allow the deletion. m_search_editor->register_key_input_callback(m_termios.c_cc[VERASE], [this](Editor& search_editor) { |