mirror of
https://github.com/zadam/trilium.git
synced 2024-11-14 19:55:10 +08:00
27 lines
940 B
JavaScript
27 lines
940 B
JavaScript
|
const eventService = require('./events');
|
||
|
const scriptService = require('./script');
|
||
|
const relationService = require('./relations');
|
||
|
const treeService = require('./tree');
|
||
|
const messagingService = require('./messaging');
|
||
|
|
||
|
eventService.subscribe(eventService.NOTE_TITLE_CHANGED, async note => {
|
||
|
const relations = await relationService.getEffectiveRelations(note.noteId, 'runOnNoteTitleChange');
|
||
|
|
||
|
for (const relation of relations) {
|
||
|
const scriptNote = await relation.getTargetNote();
|
||
|
|
||
|
await scriptService.executeNote(scriptNote, scriptNote, note);
|
||
|
}
|
||
|
|
||
|
if (!note.isRoot()) {
|
||
|
const parents = await note.getParentNotes();
|
||
|
|
||
|
for (const parent of parents) {
|
||
|
if (await parent.hasLabel("sorted")) {
|
||
|
await treeService.sortNotesAlphabetically(parent.noteId);
|
||
|
|
||
|
messagingService.sendMessageToAllClients({ type: 'refresh-tree' });
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
});
|