/* * Copyright (c) 2020, the SerenityOS developers. * * SPDX-License-Identifier: BSD-2-Clause */ #pragma once #include #include #include #include #include #include namespace Line { // FIXME: These objects are pretty heavy since they store two copies of text // somehow get rid of one. struct CompletionSuggestion { private: struct ForSearchTag { }; public: static constexpr ForSearchTag ForSearch {}; // Intentionally not explicit. (To allow suggesting bare strings) CompletionSuggestion(const String& completion) : CompletionSuggestion(completion, "", {}) { } CompletionSuggestion(const String& completion, ForSearchTag) : text_string(completion) { } CompletionSuggestion(const StringView& completion, const StringView& trailing_trivia) : CompletionSuggestion(completion, trailing_trivia, {}) { } CompletionSuggestion(const StringView& completion, const StringView& trailing_trivia, Style style); bool operator==(const CompletionSuggestion& suggestion) const { return suggestion.text_string == text_string; } Vector text; Vector trailing_trivia; Style style; size_t start_index { 0 }; size_t input_offset { 0 }; Utf32View text_view; Utf32View trivia_view; String text_string; bool is_valid { false }; }; class SuggestionManager { friend class Editor; public: void set_suggestions(Vector&& suggestions); void set_current_suggestion_initiation_index(size_t start_index); size_t count() const { return m_suggestions.size(); } size_t display_length() const { return m_last_shown_suggestion_display_length; } size_t start_index() const { return m_last_displayed_suggestion_index; } size_t next_index() const { return m_next_suggestion_index; } void set_start_index(size_t index) const { m_last_displayed_suggestion_index = index; } size_t for_each_suggestion(Function) const; enum CompletionMode { DontComplete, CompletePrefix, ShowSuggestions, CycleSuggestions, }; class CompletionAttemptResult { public: CompletionMode new_completion_mode; ssize_t new_cursor_offset { 0 }; struct { size_t start; size_t end; } offset_region_to_remove { 0, 0 }; // The region to remove as defined by [start, end) translated by (old_cursor + new_cursor_offset) Vector insert {}; Optional