mirror of
https://github.com/LadybirdBrowser/ladybird
synced 2026-05-05 06:32:30 +02:00
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. :^)
This commit is contained in:
committed by
Andreas Kling
parent
f048d16be5
commit
b0122744a6
Notes:
sideshowbarker
2024-07-18 01:36:05 +09:00
Author: https://github.com/thislooksfun Commit: https://github.com/SerenityOS/serenity/commit/b0122744a6b Pull-request: https://github.com/SerenityOS/serenity/pull/10642
@@ -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;
|
||||
|
||||
Reference in New Issue
Block a user