Use natural sort for categories

PR #19920.
This commit is contained in:
Chocobo1 2023-11-12 17:11:39 +08:00 committed by GitHub
parent 8e39ac7efd
commit b67da4bebe
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -490,20 +490,18 @@ window.addEvent('load', function() {
Object.each(category_list, function(category) { Object.each(category_list, function(category) {
sortedCategories.push(category.name); sortedCategories.push(category.name);
}); });
sortedCategories.sort(function(category1, category2) { sortedCategories.sort((leftCategory, rightCategory) => {
for (let i = 0; i < Math.min(category1.length, category2.length); ++i) { const leftSegments = leftCategory.split('/');
if (category1[i] === "/" && category2[i] !== "/") { const rightSegments = rightCategory.split('/');
return -1;
} for (let i = 0, iMax = Math.min(leftSegments.length, rightSegments.length); i < iMax; ++i) {
else if (category1[i] !== "/" && category2[i] === "/") { const compareResult = window.qBittorrent.Misc.naturalSortCollator.compare(
return 1; leftSegments[i], rightSegments[i]);
} if (compareResult !== 0)
else if (category1[i] !== category2[i]) { return compareResult;
return category1[i].localeCompare(category2[i]);
}
} }
return category1.length - category2.length; return leftSegments.length - rightSegments.length;
}); });
for (let i = 0; i < sortedCategories.length; ++i) { for (let i = 0; i < sortedCategories.length; ++i) {