mirror of
https://github.com/RGBCube/serenity
synced 2025-07-27 00:07:36 +00:00
LibGUI: Replace the already typed text when autocompleting
This was a great optimization before, but it locks us out of some neat features, like fuzzy matching.
This commit is contained in:
parent
f8c98cbf55
commit
96029a4ac6
1 changed files with 14 additions and 6 deletions
|
@ -178,16 +178,24 @@ void AutocompleteBox::apply_suggestion()
|
||||||
size_t partial_length = suggestion_index.data((GUI::ModelRole)AutocompleteSuggestionModel::InternalRole::PartialInputLength).to_i64();
|
size_t partial_length = suggestion_index.data((GUI::ModelRole)AutocompleteSuggestionModel::InternalRole::PartialInputLength).to_i64();
|
||||||
|
|
||||||
VERIFY(suggestion.length() >= partial_length);
|
VERIFY(suggestion.length() >= partial_length);
|
||||||
auto completion_view = suggestion.substring_view(partial_length, suggestion.length() - partial_length);
|
if (!m_editor->has_selection()) {
|
||||||
|
auto cursor = m_editor->cursor();
|
||||||
|
VERIFY(m_editor->cursor().column() >= partial_length);
|
||||||
|
|
||||||
|
TextPosition start(cursor.line(), cursor.column() - partial_length);
|
||||||
|
auto end = cursor;
|
||||||
|
m_editor->delete_text_range(TextRange(start, end));
|
||||||
|
}
|
||||||
|
|
||||||
auto completion_kind = (GUI::AutocompleteProvider::CompletionKind)suggestion_index.data((GUI::ModelRole)AutocompleteSuggestionModel::InternalRole::Kind).as_u32();
|
auto completion_kind = (GUI::AutocompleteProvider::CompletionKind)suggestion_index.data((GUI::ModelRole)AutocompleteSuggestionModel::InternalRole::Kind).as_u32();
|
||||||
|
|
||||||
String completion;
|
String completion;
|
||||||
if (completion_view.ends_with(".h") && completion_kind == GUI::AutocompleteProvider::CompletionKind::SystemInclude)
|
if (suggestion.ends_with(".h") && completion_kind == GUI::AutocompleteProvider::CompletionKind::SystemInclude)
|
||||||
completion = String::formatted("{}{}", completion_view, ">");
|
completion = String::formatted("{}{}", suggestion, ">");
|
||||||
else if (completion_view.ends_with(".h") && completion_kind == GUI::AutocompleteProvider::CompletionKind::ProjectInclude)
|
else if (suggestion.ends_with(".h") && completion_kind == GUI::AutocompleteProvider::CompletionKind::ProjectInclude)
|
||||||
completion = String::formatted("{}{}", completion_view, "\"");
|
completion = String::formatted("{}{}", suggestion, "\"");
|
||||||
else
|
else
|
||||||
completion = completion_view;
|
completion = suggestion;
|
||||||
|
|
||||||
m_editor->insert_at_cursor_or_replace_selection(completion);
|
m_editor->insert_at_cursor_or_replace_selection(completion);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue