Skip to content

Commit

Permalink
add support for "bottom" sort, closes #4277
Browse files Browse the repository at this point in the history
  • Loading branch information
zadam committed Sep 25, 2023
1 parent 964abf3 commit 984bd72
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 1 deletion.
1 change: 1 addition & 0 deletions src/services/builtin_attributes.js
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ module.exports = [
{ type: 'label', name: 'sortNatural' },
{ type: 'label', name: 'sortLocale' },
{ type: 'label', name: 'top' },
{ type: 'label', name: 'bottom' },
{ type: 'label', name: 'fullContentWidth' },
{ type: 'label', name: 'shareHiddenFromTree' },
{ type: 'label', name: 'shareAlias' },
Expand Down
9 changes: 8 additions & 1 deletion src/services/handlers.js
Original file line number Diff line number Diff line change
Expand Up @@ -171,8 +171,15 @@ function handleMaybeSortingLabel(entity) {
if (note) {
for (const parentNote of note.getParentNotes()) {
const sorted = parentNote.getLabelValue("sorted");
if (sorted === null) {
// checking specifically for null since that means the label doesn't exist
// empty valued "sorted" is still valid
continue;
}

if (sorted?.includes(entity.name)) { // hacky check if the sorting is affected by this label
if (sorted.includes(entity.name) // hacky check if this label is used in the sort
|| entity.name === "top"
|| entity.name === "bottom") {
treeService.sortNotesIfNeeded(parentNote.noteId);
}
}
Expand Down
8 changes: 8 additions & 0 deletions src/services/tree.js
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,14 @@ function sortNotes(parentNoteId, customSortBy = 'title', reverse = false, folder
return compare(topAEl, topBEl) * (reverse ? -1 : 1);
}

const bottomAEl = fetchValue(a, 'bottom');
const bottomBEl = fetchValue(b, 'bottom');

if (bottomAEl !== bottomBEl) {
// since "bottom" should not be reversible, we'll reverse it once more to nullify this effect
return compare(bottomBEl, bottomAEl) * (reverse ? -1 : 1);
}

const customAEl = fetchValue(a, customSortBy);
const customBEl = fetchValue(b, customSortBy);

Expand Down

0 comments on commit 984bd72

Please sign in to comment.