diff options
author | thislooksfun <tlf@thislooks.fun> | 2021-10-25 21:01:32 -0500 |
---|---|---|
committer | Andreas Kling <kling@serenityos.org> | 2021-11-02 17:53:22 +0100 |
commit | b0122744a6bf28eec136dcbe7b3b6038b5c6ed44 (patch) | |
tree | d043faf3ce2451eabc1d2b43d4ebe5376394c930 /Userland/Libraries/LibGUI/GMLAutocompleteProvider.cpp | |
parent | f048d16be55b9023e3dff4d7bcac04f240b74d9f (diff) | |
download | serenity-b0122744a6bf28eec136dcbe7b3b6038b5c6ed44.zip |
LibGUI: Match layout classes even after you start typing
The previous commit fixed the issue with layout classes not being
suggested at all, but there was still another issue. Once you started
typing the class name a different suggester would take over and only
show widgets. This commit makes it so it still only suggests layouts
in that situation.
This, combined with the last commit, makes autocompleting layouts way
more discoverable and user-friendly. :^)
Diffstat (limited to 'Userland/Libraries/LibGUI/GMLAutocompleteProvider.cpp')
-rw-r--r-- | Userland/Libraries/LibGUI/GMLAutocompleteProvider.cpp | 13 |
1 files changed, 13 insertions, 0 deletions
diff --git a/Userland/Libraries/LibGUI/GMLAutocompleteProvider.cpp b/Userland/Libraries/LibGUI/GMLAutocompleteProvider.cpp index 43d9396249..4d8f6ba640 100644 --- a/Userland/Libraries/LibGUI/GMLAutocompleteProvider.cpp +++ b/Userland/Libraries/LibGUI/GMLAutocompleteProvider.cpp @@ -29,12 +29,14 @@ void GMLAutocompleteProvider::provide_completions(Function<void(Vector<Entry>)> Vector<State> previous_states; bool should_push_state { true }; GUI::GMLToken* last_seen_token { nullptr }; + GUI::GMLToken* last_identifier_token { nullptr }; for (auto& token : all_tokens) { auto handle_class_child = [&] { if (token.m_type == GUI::GMLToken::Type::Identifier) { state = InIdentifier; identifier_string = token.m_view; + last_identifier_token = &token; } else if (token.m_type == GUI::GMLToken::Type::ClassMarker) { previous_states.append(AfterClassName); state = Free; @@ -129,6 +131,17 @@ void GMLAutocompleteProvider::provide_completions(Function<void(Vector<Entry>)> // TODO: Suggest braces? break; } + + if (last_identifier_token && last_identifier_token->m_end.line == last_seen_token->m_end.line && identifier_string == "layout") { + Core::ObjectClassRegistration::for_each([&](const Core::ObjectClassRegistration& registration) { + if (®istration == &layout_class || !registration.is_derived_from(layout_class)) + return; + if (registration.class_name().starts_with(class_names.last())) + identifier_entries.empend(registration.class_name(), class_names.last().length()); + }); + break; + } + Core::ObjectClassRegistration::for_each([&](const Core::ObjectClassRegistration& registration) { if (!registration.is_derived_from(widget_class)) return; |