From b3f47bb2b6617ed8a43c6235b7a9d153dc58eb95 Mon Sep 17 00:00:00 2001 From: dymani Date: Sat, 18 Mar 2023 10:18:34 +0800 Subject: [PATCH 1/2] Fix typo in backend API createOrUpdateLauncher() --- src/services/backend_script_api.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/services/backend_script_api.js b/src/services/backend_script_api.js index 50bab0c0d..bab0702f5 100644 --- a/src/services/backend_script_api.js +++ b/src/services/backend_script_api.js @@ -475,7 +475,7 @@ function BackendScriptApi(currentNote, apiParams) { const noteId = 'al_' + opts.id; const launcherNote = - becca.getNote(opts.id) || + becca.getNote(noteId) || specialNotesService.createLauncher({ noteId: noteId, parentNoteId: parentNoteId, @@ -514,7 +514,7 @@ function BackendScriptApi(currentNote, apiParams) { if (opts.icon) { launcherNote.setLabel('iconClass', `bx ${opts.icon}`); } else { - launcherNote.removeLabel('keyboardShortcut'); + launcherNote.removeLabel('iconClass'); } return {note: launcherNote}; From d31b5ac99fadfaeaf23fd809598fd0f816b629e2 Mon Sep 17 00:00:00 2001 From: zadam Date: Sun, 19 Mar 2023 22:23:58 +0100 Subject: [PATCH 2/2] add #newNotesOnTop, closes #3734 --- .../attribute_widgets/attribute_detail.js | 3 ++- src/services/builtin_attributes.js | 1 + src/services/notes.js | 21 ++++++++++--------- 3 files changed, 14 insertions(+), 11 deletions(-) diff --git a/src/public/app/widgets/attribute_widgets/attribute_detail.js b/src/public/app/widgets/attribute_widgets/attribute_detail.js index dc018836a..488f3709b 100644 --- a/src/public/app/widgets/attribute_widgets/attribute_detail.js +++ b/src/public/app/widgets/attribute_widgets/attribute_detail.js @@ -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.", diff --git a/src/services/builtin_attributes.js b/src/services/builtin_attributes.js index 1597c6599..abb569656 100644 --- a/src/services/builtin_attributes.js +++ b/src/services/builtin_attributes.js @@ -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' }, diff --git a/src/services/notes.js b/src/services/notes.js index 2c71a9a08..6dfa34cb0 100644 --- a/src/services/notes.js +++ b/src/services/notes.js @@ -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();