fix(sorting): BC! give precedence to #top notes over #sortFolderFirst

This commit is contained in:
Romain DEP. 2025-11-28 23:22:20 +01:00
parent 3cc64b5764
commit 3ecdcd9ea0

View File

@ -98,15 +98,6 @@ function sortNotes(parentNoteId: string, customSortBy: string = "title", reverse
} }
notes.sort((a, b) => { notes.sort((a, b) => {
if (foldersFirst) {
const aHasChildren = a.hasChildren();
const bHasChildren = b.hasChildren();
if ((aHasChildren && !bHasChildren) || (!aHasChildren && bHasChildren)) {
// exactly one note of the two is a directory, so the sorting will be done based on this status
return aHasChildren ? -1 : 1;
}
}
function fetchValue(note: BNote, key: string) { function fetchValue(note: BNote, key: string) {
let rawValue: string | null; let rawValue: string | null;
@ -154,6 +145,16 @@ function sortNotes(parentNoteId: string, customSortBy: string = "title", reverse
return compare(bottomBEl, bottomAEl) * (reverse ? -1 : 1); return compare(bottomBEl, bottomAEl) * (reverse ? -1 : 1);
} }
if (foldersFirst) {
const aHasChildren = a.hasChildren();
const bHasChildren = b.hasChildren();
if ((aHasChildren && !bHasChildren) || (!aHasChildren && bHasChildren)) {
// exactly one note of the two is a directory, so the sorting will be done based on this status
return aHasChildren ? -1 : 1;
}
}
const customAEl = fetchValue(a, customSortBy) ?? fetchValue(a, "title") as string; const customAEl = fetchValue(a, customSortBy) ?? fetchValue(a, "title") as string;
const customBEl = fetchValue(b, customSortBy) ?? fetchValue(b, "title") as string; const customBEl = fetchValue(b, customSortBy) ?? fetchValue(b, "title") as string;