mirror of
https://github.com/zadam/trilium.git
synced 2025-02-22 05:56:03 +08:00
note titles in jump to note start from hoisted note instead of root
This commit is contained in:
parent
6c16cdb011
commit
b774d56cf7
4 changed files with 44 additions and 13 deletions
2
package-lock.json
generated
2
package-lock.json
generated
|
@ -1,6 +1,6 @@
|
|||
{
|
||||
"name": "trilium",
|
||||
"version": "0.25.1-beta",
|
||||
"version": "0.25.2",
|
||||
"lockfileVersion": 1,
|
||||
"requires": true,
|
||||
"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 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();
|
||||
|
||||
|
|
|
@ -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 = {
|
||||
|
|
Loading…
Reference in a new issue