mirror of
https://github.com/SillyTavern/SillyTavern.git
synced 2024-12-11 17:07:07 +01:00
Fix Priority Sort
Corrected and expanded priority sort logic to sort by: First constant, then normal, then disabled, then by comment.
This commit is contained in:
parent
33a126491e
commit
28861660ef
@ -1678,11 +1678,34 @@ export function sortWorldInfoEntries(data, { customSort = null } = {}) {
|
|||||||
return aValue - bValue;
|
return aValue - bValue;
|
||||||
};
|
};
|
||||||
} else if (sortRule === 'priority') {
|
} else if (sortRule === 'priority') {
|
||||||
// First constant, then normal, then disabled.
|
// First constant, then normal, then disabled, then by comment.
|
||||||
primarySort = (a, b) => {
|
primarySort = (a, b) => {
|
||||||
const aValue = a.constant ? 0 : a.disable ? 2 : 1;
|
// Determine priority based on disable and constant flags
|
||||||
const bValue = b.constant ? 0 : b.disable ? 2 : 1;
|
const aPriority = a.disable ? 2 : a.constant ? 0 : 1;
|
||||||
return aValue - bValue;
|
const bPriority = b.disable ? 2 : b.constant ? 0 : 1;
|
||||||
|
|
||||||
|
// Compare priorities first
|
||||||
|
if (aPriority !== bPriority) {
|
||||||
|
return aPriority - bPriority;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Normalize comments for comparison, handling null/undefined
|
||||||
|
const commentA = a.comment ? a.comment.toLowerCase() : '';
|
||||||
|
const commentB = b.comment ? b.comment.toLowerCase() : '';
|
||||||
|
|
||||||
|
// Assign constant values for further comparison
|
||||||
|
const constantA = a.constant ? 0 : 1;
|
||||||
|
const constantB = b.constant ? 0 : 1;
|
||||||
|
|
||||||
|
// If priorities are equal, compare constants
|
||||||
|
if (aPriority === bPriority) {
|
||||||
|
if (constantA !== constantB) {
|
||||||
|
return constantA - constantB;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Finally, compare comments alphabetically
|
||||||
|
return commentA.localeCompare(commentB);
|
||||||
};
|
};
|
||||||
} else {
|
} else {
|
||||||
primarySort = (a, b) => {
|
primarySort = (a, b) => {
|
||||||
|
Loading…
Reference in New Issue
Block a user