mirror of
https://github.com/SerenityOS/serenity
synced 2024-10-16 12:52:46 +00:00
LibGUI: Allow completion suggestions to fill and display different text
There are times when it is nice to display one suggestion but fill something different. This lays the groundwork for allowing GMLAutocompleteProvider to automatically add ': ' to the end of suggested properties, while keeping the ': ' suffix from cluttering up the suggestion UI.
This commit is contained in:
parent
96029a4ac6
commit
a5b3c3f85f
|
@ -22,6 +22,7 @@ inline bool encode(IPC::Encoder& encoder, const GUI::AutocompleteProvider::Entry
|
|||
encoder << (u64)response.partial_input_length;
|
||||
encoder << (u32)response.kind;
|
||||
encoder << (u32)response.language;
|
||||
encoder << response.display_text;
|
||||
return true;
|
||||
}
|
||||
|
||||
|
@ -34,7 +35,8 @@ inline bool decode(IPC::Decoder& decoder, GUI::AutocompleteProvider::Entry& resp
|
|||
bool ok = decoder.decode(response.completion)
|
||||
&& decoder.decode(partial_input_length)
|
||||
&& decoder.decode(kind)
|
||||
&& decoder.decode(language);
|
||||
&& decoder.decode(language)
|
||||
&& decoder.decode(response.display_text);
|
||||
|
||||
if (ok) {
|
||||
response.kind = static_cast<GUI::AutocompleteProvider::CompletionKind>(kind);
|
||||
|
|
|
@ -33,6 +33,7 @@ public:
|
|||
__ModelRoleCustom = (int)GUI::ModelRole::Custom,
|
||||
PartialInputLength,
|
||||
Kind,
|
||||
Completion,
|
||||
};
|
||||
|
||||
virtual int row_count(const GUI::ModelIndex& = GUI::ModelIndex()) const override { return m_suggestions.size(); }
|
||||
|
@ -42,7 +43,10 @@ public:
|
|||
auto& suggestion = m_suggestions.at(index.row());
|
||||
if (role == GUI::ModelRole::Display) {
|
||||
if (index.column() == Column::Name) {
|
||||
return suggestion.completion;
|
||||
if (!suggestion.display_text.is_empty())
|
||||
return suggestion.display_text;
|
||||
else
|
||||
return suggestion.completion;
|
||||
}
|
||||
if (index.column() == Column::Icon) {
|
||||
if (suggestion.language == GUI::AutocompleteProvider::Language::Cpp) {
|
||||
|
@ -67,6 +71,9 @@ public:
|
|||
if ((int)role == InternalRole::PartialInputLength)
|
||||
return (i64)suggestion.partial_input_length;
|
||||
|
||||
if ((int)role == InternalRole::Completion)
|
||||
return suggestion.completion;
|
||||
|
||||
return {};
|
||||
}
|
||||
|
||||
|
@ -173,8 +180,8 @@ void AutocompleteBox::apply_suggestion()
|
|||
if (!selected_index.is_valid() || !m_suggestion_view->model()->is_within_range(selected_index))
|
||||
return;
|
||||
|
||||
auto suggestion_index = m_suggestion_view->model()->index(selected_index.row(), AutocompleteSuggestionModel::Column::Name);
|
||||
auto suggestion = suggestion_index.data().to_string();
|
||||
auto suggestion_index = m_suggestion_view->model()->index(selected_index.row());
|
||||
auto suggestion = suggestion_index.data((GUI::ModelRole)AutocompleteSuggestionModel::InternalRole::Completion).to_string();
|
||||
size_t partial_length = suggestion_index.data((GUI::ModelRole)AutocompleteSuggestionModel::InternalRole::PartialInputLength).to_i64();
|
||||
|
||||
VERIFY(suggestion.length() >= partial_length);
|
||||
|
|
|
@ -37,6 +37,7 @@ public:
|
|||
size_t partial_input_length { 0 };
|
||||
CompletionKind kind { CompletionKind::Identifier };
|
||||
Language language { Language::Unspecified };
|
||||
String display_text {};
|
||||
};
|
||||
|
||||
struct ProjectLocation {
|
||||
|
|
Loading…
Reference in a new issue