mirror of
https://github.com/zadam/trilium.git
synced 2025-06-06 18:08:33 +02:00
becca should also keep correct branch order, e.g. for export, #2346
This commit is contained in:
parent
d7cae7d5bb
commit
a863da1dce
@ -34,7 +34,11 @@ function load() {
|
|||||||
new BNote().update(row).init();
|
new BNote().update(row).init();
|
||||||
}
|
}
|
||||||
|
|
||||||
for (const row of sql.getRawRows(`SELECT branchId, noteId, parentNoteId, prefix, notePosition, isExpanded, utcDateModified FROM branches WHERE isDeleted = 0`)) {
|
const branchRows = sql.getRawRows(`SELECT branchId, noteId, parentNoteId, prefix, notePosition, isExpanded, utcDateModified FROM branches WHERE isDeleted = 0`);
|
||||||
|
// in-memory sort is faster than in the DB
|
||||||
|
branchRows.sort((a, b) => a.notePosition - b.notePosition);
|
||||||
|
|
||||||
|
for (const row of branchRows) {
|
||||||
new BBranch().update(row).init();
|
new BBranch().update(row).init();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -164,6 +168,12 @@ function branchUpdated(branch) {
|
|||||||
childNote.flatTextCache = null;
|
childNote.flatTextCache = null;
|
||||||
childNote.sortParents();
|
childNote.sortParents();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const parentNote = becca.notes[branch.parentNoteId];
|
||||||
|
|
||||||
|
if (parentNote) {
|
||||||
|
parentNote.sortChildren();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function attributeDeleted(attributeId) {
|
function attributeDeleted(attributeId) {
|
||||||
|
@ -730,6 +730,21 @@ class BNote extends AbstractBeccaEntity {
|
|||||||
.filter(note => !!note);
|
.filter(note => !!note);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
sortChildren() {
|
||||||
|
if (this.children.length === 0) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
const becca = this.becca;
|
||||||
|
|
||||||
|
this.children.sort((a, b) => {
|
||||||
|
const aBranch = becca.getBranchFromChildAndParent(a.noteId, this.noteId);
|
||||||
|
const bBranch = becca.getBranchFromChildAndParent(b.noteId, this.noteId);
|
||||||
|
|
||||||
|
return aBranch?.notePosition < bBranch?.notePosition ? -1 : 1;
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* This is used for:
|
* This is used for:
|
||||||
* - fast searching
|
* - fast searching
|
||||||
|
Loading…
x
Reference in New Issue
Block a user