mirror of
https://github.com/RGBCube/serenity
synced 2025-07-26 03:37:43 +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
3 changed files with 14 additions and 4 deletions
|
@ -22,6 +22,7 @@ inline bool encode(IPC::Encoder& encoder, const GUI::AutocompleteProvider::Entry
|
||||||
encoder << (u64)response.partial_input_length;
|
encoder << (u64)response.partial_input_length;
|
||||||
encoder << (u32)response.kind;
|
encoder << (u32)response.kind;
|
||||||
encoder << (u32)response.language;
|
encoder << (u32)response.language;
|
||||||
|
encoder << response.display_text;
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -34,7 +35,8 @@ inline bool decode(IPC::Decoder& decoder, GUI::AutocompleteProvider::Entry& resp
|
||||||
bool ok = decoder.decode(response.completion)
|
bool ok = decoder.decode(response.completion)
|
||||||
&& decoder.decode(partial_input_length)
|
&& decoder.decode(partial_input_length)
|
||||||
&& decoder.decode(kind)
|
&& decoder.decode(kind)
|
||||||
&& decoder.decode(language);
|
&& decoder.decode(language)
|
||||||
|
&& decoder.decode(response.display_text);
|
||||||
|
|
||||||
if (ok) {
|
if (ok) {
|
||||||
response.kind = static_cast<GUI::AutocompleteProvider::CompletionKind>(kind);
|
response.kind = static_cast<GUI::AutocompleteProvider::CompletionKind>(kind);
|
||||||
|
|
|
@ -33,6 +33,7 @@ public:
|
||||||
__ModelRoleCustom = (int)GUI::ModelRole::Custom,
|
__ModelRoleCustom = (int)GUI::ModelRole::Custom,
|
||||||
PartialInputLength,
|
PartialInputLength,
|
||||||
Kind,
|
Kind,
|
||||||
|
Completion,
|
||||||
};
|
};
|
||||||
|
|
||||||
virtual int row_count(const GUI::ModelIndex& = GUI::ModelIndex()) const override { return m_suggestions.size(); }
|
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());
|
auto& suggestion = m_suggestions.at(index.row());
|
||||||
if (role == GUI::ModelRole::Display) {
|
if (role == GUI::ModelRole::Display) {
|
||||||
if (index.column() == Column::Name) {
|
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 (index.column() == Column::Icon) {
|
||||||
if (suggestion.language == GUI::AutocompleteProvider::Language::Cpp) {
|
if (suggestion.language == GUI::AutocompleteProvider::Language::Cpp) {
|
||||||
|
@ -67,6 +71,9 @@ public:
|
||||||
if ((int)role == InternalRole::PartialInputLength)
|
if ((int)role == InternalRole::PartialInputLength)
|
||||||
return (i64)suggestion.partial_input_length;
|
return (i64)suggestion.partial_input_length;
|
||||||
|
|
||||||
|
if ((int)role == InternalRole::Completion)
|
||||||
|
return suggestion.completion;
|
||||||
|
|
||||||
return {};
|
return {};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -173,8 +180,8 @@ void AutocompleteBox::apply_suggestion()
|
||||||
if (!selected_index.is_valid() || !m_suggestion_view->model()->is_within_range(selected_index))
|
if (!selected_index.is_valid() || !m_suggestion_view->model()->is_within_range(selected_index))
|
||||||
return;
|
return;
|
||||||
|
|
||||||
auto suggestion_index = m_suggestion_view->model()->index(selected_index.row(), AutocompleteSuggestionModel::Column::Name);
|
auto suggestion_index = m_suggestion_view->model()->index(selected_index.row());
|
||||||
auto suggestion = suggestion_index.data().to_string();
|
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();
|
size_t partial_length = suggestion_index.data((GUI::ModelRole)AutocompleteSuggestionModel::InternalRole::PartialInputLength).to_i64();
|
||||||
|
|
||||||
VERIFY(suggestion.length() >= partial_length);
|
VERIFY(suggestion.length() >= partial_length);
|
||||||
|
|
|
@ -37,6 +37,7 @@ public:
|
||||||
size_t partial_input_length { 0 };
|
size_t partial_input_length { 0 };
|
||||||
CompletionKind kind { CompletionKind::Identifier };
|
CompletionKind kind { CompletionKind::Identifier };
|
||||||
Language language { Language::Unspecified };
|
Language language { Language::Unspecified };
|
||||||
|
String display_text {};
|
||||||
};
|
};
|
||||||
|
|
||||||
struct ProjectLocation {
|
struct ProjectLocation {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue