add #newNotesOnTop, closes #3734

This commit is contained in:
zadam
2023-03-19 22:23:58 +01:00
parent bfbb531863
commit d31b5ac99f
3 changed files with 14 additions and 11 deletions

View File

@@ -22,17 +22,18 @@ const htmlSanitizer = require("./html_sanitizer");
const ValidationError = require("../errors/validation_error");
const noteTypesService = require("./note_types");
function getNewNotePosition(parentNoteId) {
const note = becca.notes[parentNoteId];
function getNewNotePosition(parentNote) {
if (parentNote.hasLabel('newNotesOnTop')) {
const minNotePos = parentNote.getChildBranches()
.reduce((min, note) => Math.min(min, note.notePosition), 0);
if (!note) {
throw new Error(`Can't find note ${parentNoteId}`);
return minNotePos - 10;
} else {
const maxNotePos = parentNote.getChildBranches()
.reduce((max, note) => Math.max(max, note.notePosition), 0);
return maxNotePos + 10;
}
const maxNotePos = note.getChildBranches()
.reduce((max, note) => Math.max(max, note.notePosition), 0);
return maxNotePos + 10;
}
function triggerNoteTitleChanged(note) {
@@ -186,7 +187,7 @@ function createNewNote(params) {
branch = new BBranch({
noteId: note.noteId,
parentNoteId: params.parentNoteId,
notePosition: params.notePosition !== undefined ? params.notePosition : getNewNotePosition(params.parentNoteId),
notePosition: params.notePosition !== undefined ? params.notePosition : getNewNotePosition(parentNote),
prefix: params.prefix,
isExpanded: !!params.isExpanded
}).save();