diff --git a/docs/backend_api/entities_branch.js.html b/docs/backend_api/entities_branch.js.html
index e76ded267..7a4d69a8f 100644
--- a/docs/backend_api/entities_branch.js.html
+++ b/docs/backend_api/entities_branch.js.html
@@ -70,7 +70,7 @@ class Branch extends Entity {
async beforeSaving() {
if (this.notePosition === undefined) {
const maxNotePos = await sql.getValue('SELECT MAX(notePosition) FROM branches WHERE parentNoteId = ? AND isDeleted = 0', [this.parentNoteId]);
- this.notePosition = maxNotePos === null ? 0 : maxNotePos + 1;
+ this.notePosition = maxNotePos === null ? 0 : maxNotePos + 10;
}
if (!this.isDeleted) {
diff --git a/docs/frontend_api/FrontendScriptApi.html b/docs/frontend_api/FrontendScriptApi.html
index f654b2fb8..6f60a7867 100644
--- a/docs/frontend_api/FrontendScriptApi.html
+++ b/docs/frontend_api/FrontendScriptApi.html
@@ -81,7 +81,7 @@
Source:
@@ -223,7 +223,7 @@
Source:
@@ -333,7 +333,7 @@
Source:
@@ -446,7 +446,7 @@
Source:
@@ -552,7 +552,7 @@
Source:
@@ -662,7 +662,7 @@
Source:
@@ -771,7 +771,7 @@
Source:
@@ -900,7 +900,7 @@
Source:
@@ -1055,7 +1055,7 @@
Source:
@@ -1210,7 +1210,7 @@
Source:
@@ -1390,7 +1390,7 @@
Source:
@@ -1523,7 +1523,7 @@
Source:
@@ -1629,7 +1629,7 @@
Source:
@@ -1735,7 +1735,7 @@
Source:
@@ -1894,7 +1894,7 @@
Source:
@@ -2001,7 +2001,7 @@ if some action needs to happen on only one specific instance.
Source:
@@ -2156,7 +2156,7 @@ if some action needs to happen on only one specific instance.
Source:
@@ -2312,7 +2312,7 @@ if some action needs to happen on only one specific instance.
Source:
@@ -2513,7 +2513,7 @@ otherwise (by e.g. createNoteLink())
Source:
@@ -2619,7 +2619,7 @@ otherwise (by e.g. createNoteLink())
Source:
@@ -2774,7 +2774,7 @@ otherwise (by e.g. createNoteLink())
Source:
@@ -2883,7 +2883,7 @@ note.
Source:
@@ -3038,7 +3038,7 @@ note.
Source:
@@ -3171,7 +3171,7 @@ note.
Source:
@@ -3277,7 +3277,7 @@ note.
Source:
@@ -3365,7 +3365,7 @@ note.
Source:
@@ -3419,7 +3419,7 @@ note.
- reloadChildren(noteId)
+ reloadNotesAndTheirChildren(noteId)
@@ -3516,7 +3516,7 @@ note.
Source:
@@ -3649,7 +3649,7 @@ note.
Source:
@@ -3810,7 +3810,7 @@ Internally this serializes the anonymous function into string and sends it to ba
Source:
@@ -3970,7 +3970,7 @@ Internally this serializes the anonymous function into string and sends it to ba
Source:
@@ -4126,7 +4126,7 @@ Internally this serializes the anonymous function into string and sends it to ba
Source:
@@ -4180,6 +4180,161 @@ Internally this serializes the anonymous function into string and sends it to ba
+ setHoistedNoteId(noteId) → {Promise}
+
+
+
+
+
+
+
+ Hoist note. See https://github.com/zadam/trilium/wiki/Note-hoisting
+
+
+
+
+
+
+
+
+
+
+ Parameters:
+
+
+
+
+
+
+ Name |
+
+
+ Type |
+
+
+
+
+
+ Description |
+
+
+
+
+
+
+
+
+ noteId |
+
+
+
+
+
+string
+
+
+
+ |
+
+
+
+
+
+ set hoisted note. 'root' will effectively unhoist |
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ - Source:
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+Returns:
+
+
+
+
+
+ -
+ Type
+
+ -
+
+Promise
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
@@ -4277,7 +4432,7 @@ Internally this serializes the anonymous function into string and sends it to ba
Source:
@@ -4414,7 +4569,7 @@ Internally this serializes the anonymous function into string and sends it to ba
Source:
@@ -4551,7 +4706,7 @@ Internally this serializes the anonymous function into string and sends it to ba
Source:
diff --git a/docs/frontend_api/global.html b/docs/frontend_api/global.html
index 6e4c07a95..22f49fed0 100644
--- a/docs/frontend_api/global.html
+++ b/docs/frontend_api/global.html
@@ -303,7 +303,7 @@
Source:
diff --git a/docs/frontend_api/services_frontend_script_api.js.html b/docs/frontend_api/services_frontend_script_api.js.html
index 4d684ad79..9d0d2c600 100644
--- a/docs/frontend_api/services_frontend_script_api.js.html
+++ b/docs/frontend_api/services_frontend_script_api.js.html
@@ -37,6 +37,8 @@ import noteTooltipService from './note_tooltip.js';
import protectedSessionService from './protected_session.js';
import dateNotesService from './date_notes.js';
import StandardWidget from '../widgets/standard_widget.js';
+import ws from "./ws.js";
+import hoistedNoteService from "./hoisted_note.js";
/**
* This is the main frontend API interface for scripts. It's published in the local "api" object.
@@ -170,9 +172,14 @@ function FrontendScriptApi(startNote, currentNote, originEntity = null, tabConte
currentNoteId: currentNote.noteId,
originEntityName: "notes", // currently there's no other entity on frontend which can trigger event
originEntityId: originEntity ? originEntity.noteId : null
+ }, {
+ 'trilium-source-id': "script"
});
if (ret.success) {
+ // wait until all the changes done in the script has been synced to frontend before continuing
+ await ws.waitForSyncId(ret.maxSyncId);
+
return ret.executionResult;
}
else {
@@ -236,7 +243,7 @@ function FrontendScriptApi(startNote, currentNote, originEntity = null, tabConte
* @param {string} noteId
* @method
*/
- this.reloadChildren = async noteId => await treeCache.reloadNotesAndTheirChildren(noteId);
+ this.reloadNotesAndTheirChildren = async noteId => await treeCache.reloadNotesAndTheirChildren(noteId);
/**
* @param {string} noteId
@@ -309,11 +316,7 @@ function FrontendScriptApi(startNote, currentNote, originEntity = null, tabConte
* @method
* @returns {Promise<string|null>} returns note path of active note or null if there isn't active note
*/
- this.getActiveTabNotePath = () => {
- const activeTabContext = noteDetailService.getActiveTabContext();
-
- return activeTabContext ? activeTabContext.notePath : null;
- };
+ this.getActiveTabNotePath = noteDetailService.getActiveTabNotePath;
/**
* This method checks whether user navigated away from the note from which the scripts has been started.
@@ -379,6 +382,15 @@ function FrontendScriptApi(startNote, currentNote, originEntity = null, tabConte
* @return {Promise<NoteShort>}
*/
this.getYearNote = dateNotesService.getYearNote;
+
+ /**
+ * Hoist note. See https://github.com/zadam/trilium/wiki/Note-hoisting
+ *
+ * @method
+ * @param {string} noteId - set hoisted note. 'root' will effectively unhoist
+ * @return {Promise}
+ */
+ this.setHoistedNoteId = hoistedNoteService.setHoistedNoteId;
}
export default FrontendScriptApi;
diff --git a/src/public/javascripts/services/frontend_script_api.js b/src/public/javascripts/services/frontend_script_api.js
index 74de2c6cd..edb3dc199 100644
--- a/src/public/javascripts/services/frontend_script_api.js
+++ b/src/public/javascripts/services/frontend_script_api.js
@@ -10,6 +10,7 @@ import protectedSessionService from './protected_session.js';
import dateNotesService from './date_notes.js';
import StandardWidget from '../widgets/standard_widget.js';
import ws from "./ws.js";
+import hoistedNoteService from "./hoisted_note.js";
/**
* This is the main frontend API interface for scripts. It's published in the local "api" object.
@@ -353,6 +354,15 @@ function FrontendScriptApi(startNote, currentNote, originEntity = null, tabConte
* @return {Promise}
*/
this.getYearNote = dateNotesService.getYearNote;
+
+ /**
+ * Hoist note. See https://github.com/zadam/trilium/wiki/Note-hoisting
+ *
+ * @method
+ * @param {string} noteId - set hoisted note. 'root' will effectively unhoist
+ * @return {Promise}
+ */
+ this.setHoistedNoteId = hoistedNoteService.setHoistedNoteId;
}
export default FrontendScriptApi;
\ No newline at end of file
diff --git a/src/public/javascripts/services/tab_context.js b/src/public/javascripts/services/tab_context.js
index c4e4d0da5..3c444d1d9 100644
--- a/src/public/javascripts/services/tab_context.js
+++ b/src/public/javascripts/services/tab_context.js
@@ -411,11 +411,13 @@ class TabContext {
}
async remove() {
- // sometimes there are orphan autocompletes after closing the tab
- this.cleanup();
+ if (this.$tabContent) {
+ // sometimes there are orphan autocompletes after closing the tab
+ this.cleanup();
- await this.saveNoteIfChanged();
- this.$tabContent.remove();
+ await this.saveNoteIfChanged();
+ this.$tabContent.remove();
+ }
}
cleanup() {