mirror of
https://github.com/RGBCube/serenity
synced 2025-07-26 07:57:47 +00:00
LibLine: Reset suggestion state on any non-tab key
This fixes the following (and more!): ```sh $ /bin/dis<tab><tab><backspace><backspace><backspace><backspace><tab> $ /bink_benchmark ```
This commit is contained in:
parent
7e72285049
commit
084a5c6a90
2 changed files with 33 additions and 18 deletions
|
@ -27,6 +27,7 @@
|
||||||
#include "Editor.h"
|
#include "Editor.h"
|
||||||
#include <AK/GenericLexer.h>
|
#include <AK/GenericLexer.h>
|
||||||
#include <AK/JsonObject.h>
|
#include <AK/JsonObject.h>
|
||||||
|
#include <AK/ScopeGuard.h>
|
||||||
#include <AK/StringBuilder.h>
|
#include <AK/StringBuilder.h>
|
||||||
#include <AK/Utf32View.h>
|
#include <AK/Utf32View.h>
|
||||||
#include <AK/Utf8View.h>
|
#include <AK/Utf8View.h>
|
||||||
|
@ -653,14 +654,18 @@ void Editor::handle_read_event()
|
||||||
// There's nothing interesting to do here.
|
// There's nothing interesting to do here.
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
cleanup_suggestions();
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
case InputState::GotEscapeFollowedByLeftBracket:
|
case InputState::GotEscapeFollowedByLeftBracket:
|
||||||
switch (code_point) {
|
if (code_point == 'O') {
|
||||||
case 'O': // mod_ctrl
|
// mod_ctrl
|
||||||
ctrl_held = true;
|
ctrl_held = true;
|
||||||
continue;
|
continue;
|
||||||
|
}
|
||||||
|
cleanup_suggestions();
|
||||||
|
switch (code_point) {
|
||||||
case 'A': // ^[[A: arrow up
|
case 'A': // ^[[A: arrow up
|
||||||
search_backwards();
|
search_backwards();
|
||||||
m_state = InputState::Free;
|
m_state = InputState::Free;
|
||||||
|
@ -721,11 +726,15 @@ void Editor::handle_read_event()
|
||||||
case InputState::Free:
|
case InputState::Free:
|
||||||
if (code_point == 27) {
|
if (code_point == 27) {
|
||||||
m_state = InputState::GotEscape;
|
m_state = InputState::GotEscape;
|
||||||
|
cleanup_suggestions();
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
break;
|
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.
|
// 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.
|
// Process this here since the keybinds might override its behaviour.
|
||||||
if (code_point == m_termios.c_cc[VEOF] && m_cursor == 0) {
|
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
|
m_search_offset = 0; // reset search offset on any key
|
||||||
|
|
||||||
if (code_point == '\t' || reverse_tab) {
|
if (code_point == '\t' || reverse_tab) {
|
||||||
|
suggestion_cleanup.disarm();
|
||||||
|
|
||||||
if (!on_tab_complete)
|
if (!on_tab_complete)
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
|
@ -840,6 +851,19 @@ void Editor::handle_read_event()
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
insert(code_point);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (consumed_code_points == m_incomplete_data.size()) {
|
||||||
|
m_incomplete_data.clear();
|
||||||
|
} else {
|
||||||
|
for (size_t i = 0; i < consumed_code_points; ++i)
|
||||||
|
m_incomplete_data.take_first();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void Editor::cleanup_suggestions()
|
||||||
|
{
|
||||||
if (m_times_tab_pressed) {
|
if (m_times_tab_pressed) {
|
||||||
// Apply the style of the last suggestion.
|
// Apply the style of the last suggestion.
|
||||||
readjust_anchored_styles(m_suggestion_manager.current_suggestion().start_index, ModificationKind::ForcedOverlapRemoval);
|
readjust_anchored_styles(m_suggestion_manager.current_suggestion().start_index, ModificationKind::ForcedOverlapRemoval);
|
||||||
|
@ -855,16 +879,6 @@ void Editor::handle_read_event()
|
||||||
m_suggestion_display->finish();
|
m_suggestion_display->finish();
|
||||||
}
|
}
|
||||||
m_times_tab_pressed = 0; // Safe to say if we get here, the user didn't press TAB
|
m_times_tab_pressed = 0; // Safe to say if we get here, the user didn't press TAB
|
||||||
|
|
||||||
insert(code_point);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (consumed_code_points == m_incomplete_data.size()) {
|
|
||||||
m_incomplete_data.clear();
|
|
||||||
} else {
|
|
||||||
for (size_t i = 0; i < consumed_code_points; ++i)
|
|
||||||
m_incomplete_data.take_first();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
bool Editor::search(const StringView& phrase, bool allow_empty)
|
bool Editor::search(const StringView& phrase, bool allow_empty)
|
||||||
|
|
|
@ -335,6 +335,7 @@ private:
|
||||||
|
|
||||||
void refresh_display();
|
void refresh_display();
|
||||||
void cleanup();
|
void cleanup();
|
||||||
|
void cleanup_suggestions();
|
||||||
void really_quit_event_loop();
|
void really_quit_event_loop();
|
||||||
|
|
||||||
void restore()
|
void restore()
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue