Build your personal knowledge base with Trilium Notes
TypeScript electronelectron-appknowledge-baseknowledge-graphknowledge-managementknowledge-management-graphlocal-firstnote-managmentnote-takernote-takingnotebooknotesnotes-apppersonal-knowledge-basepersonal-wikiscriptableself-hostedself-hostingwiki
fix(sorting): BC! give precedence to #top notes over #sortFolderFirst
Romain DEP.3ecdcd9ea081
diff --git a/apps/server/src/services/tree.ts b/apps/server/src/services/tree.tsindex 05c9ecdd9b..9348bc4900 100644--- a/apps/server/src/services/tree.ts+++ b/apps/server/src/services/tree.ts@@ -98,15 +98,6 @@ function sortNotes(parentNoteId: string, customSortBy: string = "title", reverse}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) {let rawValue: string | null;@@ -154,6 +145,16 @@ function sortNotes(parentNoteId: string, customSortBy: string = "title", reversereturn 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 customBEl = fetchValue(b, customSortBy) ?? fetchValue(b, "title") as string;