Skip to content

Build your personal knowledge base with Trilium Notes

sort parent relationships so that clones in search notes appear last, fixes #1686

zadam25c2db6c3ada
diff --git a/src/public/app/entities/note_short.js b/src/public/app/entities/note_short.js
index 202aa2771f..7998cf58d5 100644
--- a/src/public/app/entities/note_short.js
+++ b/src/public/app/entities/note_short.js
@@ -158,6 +158,26 @@ class NoteShort {
return this.treeCache.getNotesFromCache(this.parents);
}
+ // will sort the parents so that non-search & non-archived are first and archived at the end
+ // this is done so that non-search & non-archived paths are always explored as first when looking for note path
+ resortParents() {
+ this.parents.sort((aNoteId, bNoteId) => {
+ const aBranchId = this.parentToBranch[aNoteId];
+
+ if (aBranchId && aBranchId.startsWith('virt-')) {
+ return 1;
+ }
+
+ const aNote = this.treeCache.getNoteFromCache([aNoteId]);
+
+ if (aNote.hasLabel('archived')) {
+ return 1;
+ }
+
+ return -1;
+ });
+ }
+
/** @returns {string[]} */
getChildNoteIds() {
return this.children;
diff --git a/src/public/app/services/tree.js b/src/public/app/services/tree.js
index 4ffa423cda..fa5b43ba94 100644
--- a/src/public/app/services/tree.js
+++ b/src/public/app/services/tree.js
@@ -56,6 +56,8 @@ async function resolveNotePathToSegments(notePath, logErrors = true) {
return;
}
+ child.resortParents();
+
const parents = child.getParentNotes();
if (!parents.length) {
diff --git a/src/services/note_cache/entities/note.js b/src/services/note_cache/entities/note.js
index 0d0da886be..25e9285039 100644
--- a/src/services/note_cache/entities/note.js
+++ b/src/services/note_cache/entities/note.js
@@ -180,10 +180,14 @@ class Note {
return !!this.ownedAttributes.find(attr => attr.type === 'label' && attr.name === 'archived' && attr.isInheritable);
}
- // will sort the parents so that non-archived are first and archived at the end
- // this is done so that non-archived paths are always explored as first when searching for note path
+ // will sort the parents so that non-search & non-archived are first and archived at the end
+ // this is done so that non-search & non-archived paths are always explored as first when looking for note path
resortParents() {
- this.parents.sort((a, b) => a.hasInheritableOwnedArchivedLabel ? 1 : -1);
+ this.parentBranches.sort((a, b) =>
+ a.branchId.startsWith('virt-')
+ || a.parentNote.hasInheritableOwnedArchivedLabel ? 1 : -1);
+
+ this.parents = this.parentBranches.map(branch => branch.parentNote);
}
/**