mirror of
				https://github.com/zadam/trilium.git
				synced 2025-11-03 20:06:08 +01:00 
			
		
		
		
	note titles in jump to note start from hoisted note instead of root
This commit is contained in:
		
							
								
								
									
										2
									
								
								package-lock.json
									
									
									
										generated
									
									
									
								
							
							
						
						
									
										2
									
								
								package-lock.json
									
									
									
										generated
									
									
									
								
							@@ -1,6 +1,6 @@
 | 
				
			|||||||
{
 | 
					{
 | 
				
			||||||
  "name": "trilium",
 | 
					  "name": "trilium",
 | 
				
			||||||
  "version": "0.25.1-beta",
 | 
					  "version": "0.25.2",
 | 
				
			||||||
  "lockfileVersion": 1,
 | 
					  "lockfileVersion": 1,
 | 
				
			||||||
  "requires": true,
 | 
					  "requires": true,
 | 
				
			||||||
  "dependencies": {
 | 
					  "dependencies": {
 | 
				
			||||||
 
 | 
				
			|||||||
							
								
								
									
										19
									
								
								src/services/hoisted_note.js
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										19
									
								
								src/services/hoisted_note.js
									
									
									
									
									
										Normal file
									
								
							@@ -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
 | 
				
			||||||
 | 
					};
 | 
				
			||||||
@@ -4,7 +4,7 @@ const eventService = require('./events');
 | 
				
			|||||||
const repository = require('./repository');
 | 
					const repository = require('./repository');
 | 
				
			||||||
const protectedSessionService = require('./protected_session');
 | 
					const protectedSessionService = require('./protected_session');
 | 
				
			||||||
const utils = require('./utils');
 | 
					const utils = require('./utils');
 | 
				
			||||||
const options = require('./options');
 | 
					const hoistedNoteService = require('./hoisted_note');
 | 
				
			||||||
 | 
					
 | 
				
			||||||
let loaded = false;
 | 
					let loaded = false;
 | 
				
			||||||
let noteTitles = {};
 | 
					let noteTitles = {};
 | 
				
			||||||
@@ -121,10 +121,8 @@ async function findNotes(query) {
 | 
				
			|||||||
        }
 | 
					        }
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    const hoistedNoteId = await options.getOption('hoistedNoteId');
 | 
					    if (hoistedNoteService.getHoistedNoteId() !== 'root') {
 | 
				
			||||||
 | 
					        results = results.filter(res => res.pathArray.includes(hoistedNoteService.getHoistedNoteId()));
 | 
				
			||||||
    if (hoistedNoteId !== 'root') {
 | 
					 | 
				
			||||||
        results = results.filter(res => res.pathArray.includes(hoistedNoteId));
 | 
					 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    // sort results by depth of the note. This is based on the assumption that more important results
 | 
					    // 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) {
 | 
					function getNoteTitleArrayForPath(path) {
 | 
				
			||||||
    const titles = [];
 | 
					    const titles = [];
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    if (path[0] === 'root') {
 | 
					    if (path[0] === hoistedNoteService.getHoistedNoteId()) {
 | 
				
			||||||
        if (path.length === 1) {
 | 
					        if (path.length === 1) {
 | 
				
			||||||
            return [ getNoteTitle('root') ];
 | 
					            return [ getNoteTitle(hoistedNoteService.getHoistedNoteId()) ];
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
        else {
 | 
					        else {
 | 
				
			||||||
            path = path.slice(1);
 | 
					            path = path.slice(1);
 | 
				
			||||||
@@ -231,11 +229,20 @@ function getNoteTitleArrayForPath(path) {
 | 
				
			|||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    let parentNoteId = 'root';
 | 
					    let parentNoteId = 'root';
 | 
				
			||||||
 | 
					    let hoistedNotePassed = false;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    for (const noteId of path) {
 | 
					    for (const noteId of path) {
 | 
				
			||||||
 | 
					        // start collecting path segment titles only after hoisted note
 | 
				
			||||||
 | 
					        if (hoistedNotePassed) {
 | 
				
			||||||
            const title = getNoteTitle(noteId, parentNoteId);
 | 
					            const title = getNoteTitle(noteId, parentNoteId);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
            titles.push(title);
 | 
					            titles.push(title);
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        if (noteId === hoistedNoteService.getHoistedNoteId()) {
 | 
				
			||||||
 | 
					            hoistedNotePassed = true;
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        parentNoteId = noteId;
 | 
					        parentNoteId = noteId;
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@@ -250,6 +257,10 @@ function getNoteTitleForPath(path) {
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
function getSomePath(noteId, path) {
 | 
					function getSomePath(noteId, path) {
 | 
				
			||||||
    if (noteId === 'root') {
 | 
					    if (noteId === 'root') {
 | 
				
			||||||
 | 
					        if (!path.includes(hoistedNoteService.getHoistedNoteId())) {
 | 
				
			||||||
 | 
					            return false;
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        path.push(noteId);
 | 
					        path.push(noteId);
 | 
				
			||||||
        path.reverse();
 | 
					        path.reverse();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -94,9 +94,10 @@ async function updateEntity(entity) {
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
        const primaryKey = entity[primaryKeyName];
 | 
					        const primaryKey = entity[primaryKeyName];
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        if (entity.isChanged && (entityName !== 'options' || entity.isSynced)) {
 | 
					        if (entity.isChanged) {
 | 
				
			||||||
 | 
					            if (entityName !== 'options' || entity.isSynced) {
 | 
				
			||||||
                await syncTableService.addEntitySync(entityName, primaryKey);
 | 
					                await syncTableService.addEntitySync(entityName, primaryKey);
 | 
				
			||||||
 | 
					            }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
            if (!cls.isEntityEventsDisabled()) {
 | 
					            if (!cls.isEntityEventsDisabled()) {
 | 
				
			||||||
                const eventPayload = {
 | 
					                const eventPayload = {
 | 
				
			||||||
 
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user