Skip to content
This repository has been archived by the owner on Dec 6, 2024. It is now read-only.

Use natural sort for categories #27

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 13 additions & 1 deletion private/scripts/client.js
Original file line number Diff line number Diff line change
Expand Up @@ -488,7 +488,19 @@ window.addEvent('load', function() {
Object.each(category_list, function(category) {
sortedCategories.push(category.name);
});
sortedCategories.sort();
sortedCategories.sort((leftCategory, rightCategory) => {
const leftSegments = leftCategory.split('/');
const rightSegments = rightCategory.split('/');

for (let i = 0, iMax = Math.min(leftSegments.length, rightSegments.length); i < iMax; ++i) {
const compareResult = window.qBittorrent.Misc.naturalSortCollator.compare(
leftSegments[i], rightSegments[i]);
if (compareResult !== 0)
return compareResult;
}

return leftSegments.length - rightSegments.length;
});

for (let i = 0; i < sortedCategories.length; ++i) {
const categoryName = sortedCategories[i];
Expand Down