Skip to content

Build your personal knowledge base with Trilium Notes

note titles in jump to note start from hoisted note instead of root

azivnerb774d56cf789
diff --git a/package-lock.json b/package-lock.json
index 74d39e6937..ba25389806 100644
--- a/package-lock.json
+++ b/package-lock.json
@@ -1,6 +1,6 @@
{
"name": "trilium",
- "version": "0.25.1-beta",
+ "version": "0.25.2",
"lockfileVersion": 1,
"requires": true,
"dependencies": {
diff --git a/src/services/hoisted_note.js b/src/services/hoisted_note.js
new file mode 100644
index 0000000000..dc9536bc96
--- /dev/null
+++ b/src/services/hoisted_note.js
@@ -0,0 +1,19 @@
+const optionService = require('./options');
+const sqlInit = require('./sql_init');
+const eventService = require('./events');
+
+let hoistedNoteId = 'root';
+
+eventService.subscribe(eventService.ENTITY_CHANGED, async ({entityName, entity}) => {
+ if (entityName === 'options' && entity.name === 'hoistedNoteId') {
+ hoistedNoteId = entity.value;
+ }
+});
+
+sqlInit.dbReady.then(async () => {
+ hoistedNoteId = await optionService.getOption('hoistedNoteId');
+});
+
+module.exports = {
+ getHoistedNoteId: () => hoistedNoteId
+};
\ No newline at end of file
diff --git a/src/services/note_cache.js b/src/services/note_cache.js
index babbae7aab..6c7fef2749 100644
--- a/src/services/note_cache.js
+++ b/src/services/note_cache.js
@@ -4,7 +4,7 @@ const eventService = require('./events');
const repository = require('./repository');
const protectedSessionService = require('./protected_session');
const utils = require('./utils');
-const options = require('./options');
+const hoistedNoteService = require('./hoisted_note');
let loaded = false;
let noteTitles = {};
@@ -121,10 +121,8 @@ async function findNotes(query) {
}
}
- const hoistedNoteId = await options.getOption('hoistedNoteId');
-
- if (hoistedNoteId !== 'root') {
- results = results.filter(res => res.pathArray.includes(hoistedNoteId));
+ if (hoistedNoteService.getHoistedNoteId() !== 'root') {
+ results = results.filter(res => res.pathArray.includes(hoistedNoteService.getHoistedNoteId()));
}
// sort results by depth of the note. This is based on the assumption that more important results
@@ -221,9 +219,9 @@ function getNoteTitle(noteId, parentNoteId) {
function getNoteTitleArrayForPath(path) {
const titles = [];
- if (path[0] === 'root') {
+ if (path[0] === hoistedNoteService.getHoistedNoteId()) {
if (path.length === 1) {
- return [ getNoteTitle('root') ];
+ return [ getNoteTitle(hoistedNoteService.getHoistedNoteId()) ];
}
else {
path = path.slice(1);
@@ -231,11 +229,20 @@ function getNoteTitleArrayForPath(path) {
}
let parentNoteId = 'root';
+ let hoistedNotePassed = false;
for (const noteId of path) {
- const title = getNoteTitle(noteId, parentNoteId);
+ // start collecting path segment titles only after hoisted note
+ if (hoistedNotePassed) {
+ const title = getNoteTitle(noteId, parentNoteId);
+
+ titles.push(title);
+ }
+
+ if (noteId === hoistedNoteService.getHoistedNoteId()) {
+ hoistedNotePassed = true;
+ }
- titles.push(title);
parentNoteId = noteId;
}
@@ -250,6 +257,10 @@ function getNoteTitleForPath(path) {
function getSomePath(noteId, path) {
if (noteId === 'root') {
+ if (!path.includes(hoistedNoteService.getHoistedNoteId())) {
+ return false;
+ }
+
path.push(noteId);
path.reverse();
diff --git a/src/services/repository.js b/src/services/repository.js
index 7098a61427..ee844d97d2 100644
--- a/src/services/repository.js
+++ b/src/services/repository.js
@@ -94,9 +94,10 @@ async function updateEntity(entity) {
const primaryKey = entity[primaryKeyName];
- if (entity.isChanged && (entityName !== 'options' || entity.isSynced)) {
-
- await syncTableService.addEntitySync(entityName, primaryKey);
+ if (entity.isChanged) {
+ if (entityName !== 'options' || entity.isSynced) {
+ await syncTableService.addEntitySync(entityName, primaryKey);
+ }
if (!cls.isEntityEventsDisabled()) {
const eventPayload = {