Taskbar: Sort parent categories before their children

The category sort treated a longer path as ordering ahead of its prefix,
so a nested category like "Games/Puzzles" was sorted before its parent
"Games". create_category_menu() then looked up the not-yet-created
parent menu with .value() on an empty optional, crashing the Taskbar on
startup.

Make less_than_ignore_hotkey() sort the shorter string first when one is
a prefix of the other, so a parent category always precedes its
children. This also simplifies create_category_menu() since the parent
is guaranteed to already exist.
This commit is contained in:
Linus Groh authored and Lucas Chollet committed 2026-08-24 23:44:04 +02:00
1 parent 26f766a165
commit 2069e2ebc8
1 file changed
+3 -6
+3 -6
View File
@@ -103,7 +103,9 @@ static bool less_than_ignore_hotkey(ByteString const& a, ByteString const& b)
++a_it;
++b_it;
}
return a_it != a.end();
// When one string is a prefix of the other, sort the shorter one first so
// that a parent category ("Games") precedes its children ("Games/Puzzles").
return a_it == a.end() && b_it != b.end();
}
ErrorOr<Vector<ByteString>> discover_apps_and_categories()
@@ -159,11 +161,6 @@ ErrorOr<NonnullRefPtr<GUI::Menu>> build_system_menu(GUI::Window& window)
parent_menu = system_menu;
} else {
parent_menu = app_category_menus.get(parent_category).value();
if (!parent_menu) {
create_category_menu(parent_category);
parent_menu = app_category_menus.get(parent_category).value();
VERIFY(parent_menu);
}
}
auto category_menu = parent_menu->add_submenu(String::from_byte_string(child_category).release_value_but_fixme_should_propagate_errors());
auto category_icon_path = category_icons->read_entry("16x16", category);