Skip to content

Commit

Permalink
add #newNotesOnTop, closes #3734
Browse files Browse the repository at this point in the history
  • Loading branch information
zadam committed Mar 19, 2023
1 parent bfbb531 commit d31b5ac
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 11 deletions.
3 changes: 2 additions & 1 deletion src/public/app/widgets/attribute_widgets/attribute_detail.js
Original file line number Diff line number Diff line change
Expand Up @@ -242,7 +242,8 @@ const ATTR_HELP = {
"keepCurrentHoisting": "Opening this link won't change hoisting even if the note is not displayable in the current hoisted subtree.",
"executeButton": "Title of the button which will execute the current code note",
"executeDescription": "Longer description of the current code note displayed together with the execute button",
"excludeFromNoteMap": "Notes with this label will be hidden from the Note Map"
"excludeFromNoteMap": "Notes with this label will be hidden from the Note Map",
"newNotesOnTop": "New notes will be created at the top of the parent note, not on the bottom."
},
"relation": {
"runOnNoteCreation": "executes when note is created on backend. Use this relation if you want to run the script for all notes created under a specific subtree. In that case, create it on the subtree root note and make it inheritable. A new note created within the subtree (any depth) will trigger the script.",
Expand Down
1 change: 1 addition & 0 deletions src/services/builtin_attributes.js
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ module.exports = [
{ type: 'label', name: 'keepCurrentHoisting'},
{ type: 'label', name: 'executeButton'},
{ type: 'label', name: 'executeDescription'},
{ type: 'label', name: 'newNotesOnTop'},

// relation names
{ type: 'relation', name: 'internalLink' },
Expand Down
21 changes: 11 additions & 10 deletions src/services/notes.js
Original file line number Diff line number Diff line change
Expand Up @@ -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}`);
}

const maxNotePos = note.getChildBranches()
.reduce((max, note) => Math.max(max, note.notePosition), 0);
return minNotePos - 10;
} else {
const maxNotePos = parentNote.getChildBranches()
.reduce((max, note) => Math.max(max, note.notePosition), 0);

return maxNotePos + 10;
return maxNotePos + 10;
}
}

function triggerNoteTitleChanged(note) {
Expand Down Expand Up @@ -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();
Expand Down

0 comments on commit d31b5ac

Please sign in to comment.