From b0122744a6bf28eec136dcbe7b3b6038b5c6ed44 Mon Sep 17 00:00:00 2001 From: thislooksfun Date: Mon, 25 Oct 2021 21:01:32 -0500 Subject: [PATCH] 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. :^) --- .../Libraries/LibGUI/GMLAutocompleteProvider.cpp | 13 +++++++++++++ 1 file changed, 13 insertions(+) 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)> Vector 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)> // 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;