feat(ui): sort search results by provider then name

Group aggregated search results per provider (in query order, pacman
first) and sort each group alphabetically, case-insensitively.

🤖 Generated with Codebuff
Co-Authored-By: Codebuff <noreply@codebuff.com>
This commit is contained in:
BlackAngelTV committed 2026-08-29 13:56:27 +02:00
1 parent d8a70eabf8
commit 5cc85cac4a
3 files changed
+88

No files matched your search

+37
View File
@@ -4,6 +4,8 @@
#include <vector>
#include <functional>
#include <map>
#include <algorithm>
#include <cctype>
// Information about a single package
struct PackageInfo {
@@ -71,6 +73,41 @@ inline void mergeProviderDuplicates(std::vector<PackageInfo>& packages) {
}
}
// Sort aggregated results by provider, then by name (case-insensitive), so
// packages from the same manager stay grouped. Providers are ordered by their
// position in providerOrder (query order); providers absent from it sort last
// and are compared by id.
inline void sortByProviderThenName(std::vector<PackageInfo>& packages,
const std::vector<std::string>& providerOrder = {}) {
auto ciLess = [](const std::string& a, const std::string& b) {
std::size_t i = 0;
for (; i < a.size() && i < b.size(); ++i) {
unsigned char ca =
static_cast<unsigned char>(std::tolower(static_cast<unsigned char>(a[i])));
unsigned char cb =
static_cast<unsigned char>(std::tolower(static_cast<unsigned char>(b[i])));
if (ca != cb) return ca < cb;
}
return a.size() < b.size();
};
auto rank = [&](const std::string& id) {
for (std::size_t i = 0; i < providerOrder.size(); ++i) {
if (providerOrder[i] == id) return static_cast<int>(i);
}
return static_cast<int>(providerOrder.size());
};
std::stable_sort(packages.begin(), packages.end(),
[&](const PackageInfo& a, const PackageInfo& b) {
int ra = rank(a.provider);
int rb = rank(b.provider);
if (ra != rb) return ra < rb;
if (a.provider != b.provider) return a.provider < b.provider;
return ciLess(a.name, b.name);
});
}
// Abstract interface for the package manager
class IPackageManager {
public: