mirror of
https://github.com/DominikDoom/a1111-sd-webui-tagcomplete.git
synced 2026-01-26 19:19:57 +00:00
Small cleanup, add reverse option
Properly add text at the end on non-reverse numeric
This commit is contained in:
@@ -214,26 +214,35 @@ function observeElement(element, property, callback, delay = 0) {
|
||||
// Sort functions
|
||||
function getSortFunction() {
|
||||
let criterion = TAC_CFG.modelSortOrder || "Name";
|
||||
|
||||
const textSort = (a, b, reverse = false) => {
|
||||
const textHolderA = a.type === ResultType.chant ? a.aliases : a.text;
|
||||
const textHolderB = b.type === ResultType.chant ? b.aliases : b.text;
|
||||
|
||||
const aKey = a.sortKey || textHolderA;
|
||||
const bKey = b.sortKey || textHolderB;
|
||||
return reverse ? bKey.localeCompare(aKey) : aKey.localeCompare(bKey);
|
||||
}
|
||||
const numericSort = (a, b, reverse = false) => {
|
||||
const noKey = reverse ? "-1" : Number.MAX_SAFE_INTEGER;
|
||||
let aParsed = parseFloat(a.sortKey || noKey);
|
||||
let bParsed = parseFloat(b.sortKey || noKey);
|
||||
|
||||
if (aParsed === bParsed) {
|
||||
return textSort(a, b, false);
|
||||
}
|
||||
|
||||
return reverse ? bParsed - aParsed : aParsed - bParsed;
|
||||
}
|
||||
|
||||
return (a, b) => {
|
||||
let textHolderA = a.type === ResultType.chant ? a.aliases : a.text;
|
||||
let textHolderB = b.type === ResultType.chant ? b.aliases : b.text;
|
||||
|
||||
switch (criterion) {
|
||||
case "Date Modified":
|
||||
let aParsed = parseFloat(a.sortKey || "-1");
|
||||
let bParsed = parseFloat(b.sortKey || "-1");
|
||||
|
||||
if (aParsed === bParsed) {
|
||||
let aKey = a.sortKey || textHolderA;
|
||||
let bKey = b.sortKey || textHolderB;
|
||||
return aKey.localeCompare(bKey);
|
||||
}
|
||||
|
||||
return bParsed - aParsed;
|
||||
case "Date Modified (newest first)":
|
||||
return numericSort(a, b, true);
|
||||
case "Date Modified (oldest first)":
|
||||
return numericSort(a, b, false);
|
||||
default:
|
||||
let aKey = a.sortKey || textHolderA;
|
||||
let bKey = b.sortKey || textHolderB;
|
||||
return aKey.localeCompare(bKey);
|
||||
return textSort(a, b);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user