take branch prefix into account while sorting, fixes #3896

This commit is contained in:
zadam 2023-05-03 23:42:44 +02:00
parent fbffc6b2b5
commit 9b32d86f78
2 changed files with 18 additions and 5 deletions

View File

@ -61,6 +61,12 @@ eventService.subscribe([ eventService.ENTITY_CHANGED, eventService.ENTITY_DELETE
eventService.subscribe(eventService.ENTITY_CHANGED, ({entityName, entity}) => {
if (entityName === 'note_contents') { // FIXME
runAttachedRelations(entity, 'runOnNoteContentChange', entity);
} else if (entityName === 'branches') {
const parentNote = becca.getNote(entity.parentNoteId);
if (parentNote?.hasLabel("sorted")) {
treeService.sortNotesIfNeeded(parentNote.noteId);
}
}
});

View File

@ -90,22 +90,29 @@ function sortNotes(parentNoteId, customSortBy = 'title', reverse = false, folder
}
function fetchValue(note, key) {
const rawValue = ['title', 'dateCreated', 'dateModified'].includes(key)
? note[key]
: note.getLabelValue(key);
let rawValue;
if (key === 'title') {
const branch = note.getParentBranches().find(branch => branch.parentNoteId === parentNoteId);
const prefix = branch?.prefix;
rawValue = prefix ? `${prefix} - ${note.title}` : note.title;
} else {
rawValue = ['dateCreated', 'dateModified'].includes(key)
? note[key]
: note.getLabelValue(key);
}
return normalize(rawValue);
}
function compare(a, b) {
if (!sortNatural){
if (!sortNatural) {
// alphabetical sort
return b === null || b === undefined || a < b ? -1 : 1;
} else {
// natural sort
return a.localeCompare(b, sortLocale, {numeric: true, sensitivity: 'base'});
}
}
const topAEl = fetchValue(a, 'top');