1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-05-31 14:48:14 +00:00

LibLine: Add a constructor for CompletionSuggestions purely for comparison

`CompletionSuggestion(text, ForSearch)` creates a suggestion whose only
purpose is to be compared against.
This constructor skips initialising the views.
This commit is contained in:
AnotherTest 2020-05-22 22:40:42 +04:30 committed by Andreas Kling
parent f0862cf2b7
commit 2427f3b38b
2 changed files with 20 additions and 1 deletions

View file

@ -32,6 +32,7 @@ namespace Line {
CompletionSuggestion::CompletionSuggestion(const StringView& completion, const StringView& trailing_trivia, Style style)
: style(style)
, text_string(completion)
, is_valid(true)
{
Utf8View text_u8 { completion };
Utf8View trivia_u8 { trailing_trivia };
@ -49,6 +50,11 @@ CompletionSuggestion::CompletionSuggestion(const StringView& completion, const S
void SuggestionManager::set_suggestions(Vector<CompletionSuggestion>&& suggestions)
{
m_suggestions = move(suggestions);
// make sure we were not given invalid suggestions
for (auto& suggestion : m_suggestions)
ASSERT(suggestion.is_valid);
size_t common_suggestion_prefix { 0 };
if (m_suggestions.size() == 1) {
m_largest_common_suggestion_prefix_length = m_suggestions[0].text_view.length();