Revert "Replace multiple isDescending with reverse"

This reverts commit 793177b8bc.
This commit is contained in:
Leilei332
2025-11-08 15:22:56 +08:00
parent 793177b8bc
commit 667f3d8782
+29 -20
View File
@@ -375,13 +375,25 @@ exports.sortTiddlers = function(titles,sortField,isDescending,isCaseSensitive,is
if(sortField === "title") {
if(!isNumeric && !isAlphaNumeric) {
if(isCaseSensitive) {
titles.sort(function(a,b) {
return a.localeCompare(b, locale);
});
if(isDescending) {
titles.sort(function(a,b) {
return b.localeCompare(a, locale);
});
} else {
titles.sort(function(a,b) {
return a.localeCompare(b, locale);
});
}
} else {
titles.sort(function(a,b) {
return a.toLowerCase().localeCompare(b.toLowerCase(), locale);
});
if(isDescending) {
titles.sort(function(a,b) {
return b.toLowerCase().localeCompare(a.toLowerCase(), locale);
});
} else {
titles.sort(function(a,b) {
return a.toLowerCase().localeCompare(b.toLowerCase(), locale);
});
}
}
} else {
titles.sort(function(a,b) {
@@ -393,24 +405,24 @@ exports.sortTiddlers = function(titles,sortField,isDescending,isCaseSensitive,is
if(isNaN(y)) {
// If neither value is a number then fall through to a textual comparison
} else {
return 1;
return isDescending ? -1 : 1;
}
} else {
if(isNaN(y)) {
return -1;
return isDescending ? 1 : -1;
} else {
return x - y;
return isDescending ? y - x : x - y;
}
}
}
if(isAlphaNumeric) {
return a.localeCompare(b,locale,{numeric: true,sensitivity: "base"});
return isDescending ? b.localeCompare(a,locale,{numeric: true,sensitivity: "base"}) : a.localeCompare(b,locale,{numeric: true,sensitivity: "base"});
}
if(!isCaseSensitive) {
a = a.toLowerCase();
b = b.toLowerCase();
}
return a.localeCompare(b, locale);
return isDescending ? b.localeCompare(a, locale) : a.localeCompare(b, locale);
});
}
} else {
@@ -437,34 +449,31 @@ exports.sortTiddlers = function(titles,sortField,isDescending,isCaseSensitive,is
if(isNaN(y)) {
// If neither value is a number then fall through to a textual comparison
} else {
return 1;
return isDescending ? -1 : 1;
}
} else {
if(isNaN(y)) {
return -1;
return isDescending ? 1 : -1;
} else {
return x - y;
return isDescending ? y - x : x - y;
}
}
}
if(Object.prototype.toString.call(a) === "[object Date]" && Object.prototype.toString.call(b) === "[object Date]") {
return a - b;
return isDescending ? b - a : a - b;
}
a = String(a);
b = String(b);
if(isAlphaNumeric) {
return a.localeCompare(b,locale,{numeric: true,sensitivity: "base"});
return isDescending ? b.localeCompare(a,locale,{numeric: true,sensitivity: "base"}) : a.localeCompare(b,locale,{numeric: true,sensitivity: "base"});
}
if(!isCaseSensitive) {
a = a.toLowerCase();
b = b.toLowerCase();
}
return a.localeCompare(b, locale);
return isDescending ? b.localeCompare(a, locale) : a.localeCompare(b, locale);
});
}
if(isDescending) {
titles.reverse();
}
};
/*