diff options
author | AnotherTest <ali.mpfard@gmail.com> | 2020-04-19 18:32:28 +0430 |
---|---|---|
committer | Andreas Kling <kling@serenityos.org> | 2020-04-19 17:21:55 +0200 |
commit | cb3cf589ed8a5df38a801bbc34a21951924e9195 (patch) | |
tree | 90cf56840fe78bced5e96e11108793096aee261d /Libraries/LibLine/Editor.h | |
parent | 7ef48171ce1585d91dbd37568b8fefcd1443245e (diff) | |
download | serenity-cb3cf589ed8a5df38a801bbc34a21951924e9195.zip |
LibLine: Allow suggestions to have trailing trivia strings
These strings would be applied when inserted into the buffer, but are
not shown as part of the suggestion.
This commit also patches up Userland/js and Shell to use this
functionality
Diffstat (limited to 'Libraries/LibLine/Editor.h')
-rw-r--r-- | Libraries/LibLine/Editor.h | 30 |
1 files changed, 26 insertions, 4 deletions
diff --git a/Libraries/LibLine/Editor.h b/Libraries/LibLine/Editor.h index f5085cfcbd..ce7813d31a 100644 --- a/Libraries/LibLine/Editor.h +++ b/Libraries/LibLine/Editor.h @@ -53,6 +53,28 @@ struct KeyCallback { Function<bool(Editor&)> callback; }; +struct CompletionSuggestion { + // intentionally not explicit (allows suggesting bare strings) + CompletionSuggestion(const String& completion) + : text(completion) + , trailing_trivia("") + { + } + CompletionSuggestion(const StringView& completion, const StringView& trailing_trivia) + : text(completion) + , trailing_trivia(trailing_trivia) + { + } + + bool operator==(const CompletionSuggestion& suggestion) const + { + return suggestion.text == text; + } + + String text; + String trailing_trivia; +}; + class Editor { public: Editor(); @@ -79,8 +101,8 @@ public: void register_character_input_callback(char ch, Function<bool(Editor&)> callback); - Function<Vector<String>(const String&)> on_tab_complete_first_token; - Function<Vector<String>(const String&)> on_tab_complete_other_token; + Function<Vector<CompletionSuggestion>(const String&)> on_tab_complete_first_token; + Function<Vector<CompletionSuggestion>(const String&)> on_tab_complete_other_token; Function<void(Editor&)> on_display_refresh; // FIXME: we will have to kindly ask our instantiators to set our signal handlers @@ -195,8 +217,8 @@ private: size_t m_origin_y { 0 }; String m_new_prompt; - Vector<String> m_suggestions; - String m_last_shown_suggestion { String::empty() }; + Vector<CompletionSuggestion> m_suggestions; + CompletionSuggestion m_last_shown_suggestion { String::empty() }; size_t m_last_shown_suggestion_display_length { 0 }; bool m_last_shown_suggestion_was_complete { false }; size_t m_next_suggestion_index { 0 }; |