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(core): group folders last under #sortDirection=desc, as before
BeatLink58b1e5b0eddf
diff --git a/packages/trilium-core/src/services/tree.spec.ts b/packages/trilium-core/src/services/tree.spec.tsindex 347be489ec..ea159ae0ce 100644--- a/packages/trilium-core/src/services/tree.spec.ts+++ b/packages/trilium-core/src/services/tree.spec.ts@@ -214,7 +214,7 @@ describe("Tree", () => {expect(orderedTitles).toStrictEqual(["top", "a", "c", "b", "bottom"]);});- it("keeps folders first under #sortDirection=desc, as the label says", () => {+ it("groups folders last under #sortDirection=desc, as the single-key sort did", () => {const note = buildNote({children: [{title: "a"},@@ -230,7 +230,7 @@ describe("Tree", () => {tree.sortNotesIfNeeded(note.noteId);});const orderedTitles = note.children.map((child) => child.title);- expect(orderedTitles).toStrictEqual(["p2", "p1", "b", "a"]);+ expect(orderedTitles).toStrictEqual(["b", "a", "p2", "p1"]);});it("orders several #top and #bottom notes by their values, whatever the direction", () => {diff --git a/packages/trilium-core/src/services/tree.ts b/packages/trilium-core/src/services/tree.tsindex 512c567585..043c0b82c4 100644--- a/packages/trilium-core/src/services/tree.ts+++ b/packages/trilium-core/src/services/tree.ts@@ -105,8 +105,8 @@ export function parseSortCriteria(value: string | null | undefined): SortCriteri/*** Sorts the children of `parentNoteId` by the levels of `sortBy` (see {@link parseSortCriteria});- * a level without its own direction and the final title tiebreak follow `reverse`. `#top`,- * `#bottom` and folders take precedence over every level and ignore the direction.+ * a level without its own direction, the folders-first grouping and the final title tiebreak+ * follow `reverse`; `#top` and `#bottom` take precedence over everything and ignore it.*/function sortNotes(parentNoteId: string,@@ -185,8 +185,9 @@ function sortNotes(const aHasChildren = a.hasChildren();const bHasChildren = b.hasChildren();+ // Folders group first ascending and last descending, as the single-key sort did.if (aHasChildren !== bHasChildren) {- return aHasChildren ? -1 : 1;+ return (aHasChildren ? -1 : 1) * (reverse ? -1 : 1);}}