From 084a5c6a9041657a63f85591d4af1d82c5bb3925 Mon Sep 17 00:00:00 2001 From: AnotherTest Date: Mon, 31 Aug 2020 22:04:32 +0430 Subject: [PATCH] LibLine: Reset suggestion state on any non-tab key This fixes the following (and more!): ```sh $ /bin/dis $ /bink_benchmark ``` --- Libraries/LibLine/Editor.cpp | 50 +++++++++++++++++++++++------------- Libraries/LibLine/Editor.h | 1 + 2 files changed, 33 insertions(+), 18 deletions(-) diff --git a/Libraries/LibLine/Editor.cpp b/Libraries/LibLine/Editor.cpp index 56268920338..8f896beda6f 100644 --- a/Libraries/LibLine/Editor.cpp +++ b/Libraries/LibLine/Editor.cpp @@ -27,6 +27,7 @@ #include "Editor.h" #include #include +#include #include #include #include @@ -653,14 +654,18 @@ void Editor::handle_read_event() // There's nothing interesting to do here. } } + cleanup_suggestions(); continue; } } case InputState::GotEscapeFollowedByLeftBracket: - switch (code_point) { - case 'O': // mod_ctrl + if (code_point == 'O') { + // mod_ctrl ctrl_held = true; continue; + } + cleanup_suggestions(); + switch (code_point) { case 'A': // ^[[A: arrow up search_backwards(); m_state = InputState::Free; @@ -721,11 +726,15 @@ void Editor::handle_read_event() case InputState::Free: if (code_point == 27) { m_state = InputState::GotEscape; + cleanup_suggestions(); continue; } break; } + // There are no sequences past this point, so short of 'tab', we will want to cleanup the suggestions. + ArmedScopeGuard suggestion_cleanup { [this] { cleanup_suggestions(); } }; + // Normally ^D. `stty eof \^n` can change it to ^N (or something else), but Serenity doesn't have `stty` yet. // Process this here since the keybinds might override its behaviour. if (code_point == m_termios.c_cc[VEOF] && m_cursor == 0) { @@ -742,6 +751,8 @@ void Editor::handle_read_event() m_search_offset = 0; // reset search offset on any key if (code_point == '\t' || reverse_tab) { + suggestion_cleanup.disarm(); + if (!on_tab_complete) continue; @@ -840,22 +851,6 @@ void Editor::handle_read_event() continue; } - if (m_times_tab_pressed) { - // Apply the style of the last suggestion. - readjust_anchored_styles(m_suggestion_manager.current_suggestion().start_index, ModificationKind::ForcedOverlapRemoval); - stylize({ m_suggestion_manager.current_suggestion().start_index, m_cursor, Span::Mode::CodepointOriented }, m_suggestion_manager.current_suggestion().style); - // We probably have some suggestions drawn, - // let's clean them up. - if (m_suggestion_display->cleanup()) { - reposition_cursor(); - m_refresh_needed = true; - } - m_suggestion_manager.reset(); - suggest(0, 0, Span::CodepointOriented); - m_suggestion_display->finish(); - } - m_times_tab_pressed = 0; // Safe to say if we get here, the user didn't press TAB - insert(code_point); } @@ -867,6 +862,25 @@ void Editor::handle_read_event() } } +void Editor::cleanup_suggestions() +{ + if (m_times_tab_pressed) { + // Apply the style of the last suggestion. + readjust_anchored_styles(m_suggestion_manager.current_suggestion().start_index, ModificationKind::ForcedOverlapRemoval); + stylize({ m_suggestion_manager.current_suggestion().start_index, m_cursor, Span::Mode::CodepointOriented }, m_suggestion_manager.current_suggestion().style); + // We probably have some suggestions drawn, + // let's clean them up. + if (m_suggestion_display->cleanup()) { + reposition_cursor(); + m_refresh_needed = true; + } + m_suggestion_manager.reset(); + suggest(0, 0, Span::CodepointOriented); + m_suggestion_display->finish(); + } + m_times_tab_pressed = 0; // Safe to say if we get here, the user didn't press TAB +} + bool Editor::search(const StringView& phrase, bool allow_empty) { diff --git a/Libraries/LibLine/Editor.h b/Libraries/LibLine/Editor.h index 82c3b5b2992..1d1545f36f3 100644 --- a/Libraries/LibLine/Editor.h +++ b/Libraries/LibLine/Editor.h @@ -335,6 +335,7 @@ private: void refresh_display(); void cleanup(); + void cleanup_suggestions(); void really_quit_event_loop(); void restore()