Skip to content

Build your personal knowledge base with Trilium Notes

fix notePosition assignment for new children of root

zadam5905950c1779
diff --git a/db/migrations/0214__fix_root_children_ordering.sql b/db/migrations/0214__fix_root_children_ordering.sql
new file mode 100644
index 0000000000..056a76336f
--- /dev/null
+++ b/db/migrations/0214__fix_root_children_ordering.sql
@@ -0,0 +1 @@
+UPDATE branches SET notePosition = notePosition - 999899999 WHERE parentNoteId = 'root' AND notePosition > 999999999;
diff --git a/src/services/app_info.js b/src/services/app_info.js
index 3f5f02f3b9..88338defe3 100644
--- a/src/services/app_info.js
+++ b/src/services/app_info.js
@@ -4,7 +4,7 @@ const build = require('./build');
const packageJson = require('../../package');
const {TRILIUM_DATA_DIR} = require('./data_dir');
-const APP_DB_VERSION = 213;
+const APP_DB_VERSION = 214;
const SYNC_VERSION = 29;
const CLIPPER_PROTOCOL_VERSION = "1.0";
diff --git a/src/services/notes.js b/src/services/notes.js
index c9343bc4e9..1ec0121860 100644
--- a/src/services/notes.js
+++ b/src/services/notes.js
@@ -26,11 +26,13 @@ const fs = require("fs");
function getNewNotePosition(parentNote) {
if (parentNote.isLabelTruthy('newNotesOnTop')) {
const minNotePos = parentNote.getChildBranches()
+ .filter(branch => branch.noteId !== '_hidden') // has "always last" note position
.reduce((min, note) => Math.min(min, note.notePosition), 0);
return minNotePos - 10;
} else {
const maxNotePos = parentNote.getChildBranches()
+ .filter(branch => branch.noteId !== '_hidden') // has "always last" note position
.reduce((max, note) => Math.max(max, note.notePosition), 0);
return maxNotePos + 10;