Skip to content

Build your personal knowledge base with Trilium Notes

fix setting title

azivner7038636d2e18
diff --git a/public/javascripts/dialogs/edit_tree_prefix.js b/public/javascripts/dialogs/edit_tree_prefix.js
index 31dfc0befa..5ae40decfd 100644
--- a/public/javascripts/dialogs/edit_tree_prefix.js
+++ b/public/javascripts/dialogs/edit_tree_prefix.js
@@ -6,6 +6,8 @@ const editTreePrefix = (function() {
const treePrefixInputEl = $("#tree-prefix-input");
const noteTitleEl = $('#tree-prefix-note-title');
+ let noteTreeId;
+
async function showDialog() {
glob.activeDialog = dialogEl;
@@ -16,6 +18,8 @@ const editTreePrefix = (function() {
const currentNode = noteTree.getCurrentNode();
+ noteTreeId = currentNode.data.note_tree_id;
+
treePrefixInputEl.val(currentNode.data.prefix).focus();
const noteTitle = noteTree.getNoteTitle(currentNode.data.note_id);
@@ -25,8 +29,6 @@ const editTreePrefix = (function() {
formEl.submit(() => {
const prefix = treePrefixInputEl.val();
- const currentNode = noteTree.getCurrentNode();
- const noteTreeId = currentNode.data.note_tree_id;
$.ajax({
url: baseApiUrl + 'tree/' + noteTreeId + '/setPrefix',
@@ -35,15 +37,7 @@ const editTreePrefix = (function() {
data: JSON.stringify({
prefix: prefix
}),
- success: () => {
- currentNode.data.prefix = prefix;
-
- const noteTitle = noteTree.getNoteTitle(currentNode.data.note_id);
-
- const title = (prefix ? (prefix + " - ") : "") + noteTitle;
-
- currentNode.setTitle(title);
- },
+ success: () => noteTree.setPrefix(noteTreeId, prefix),
error: () => showError("Error setting prefix.")
});
diff --git a/public/javascripts/note_tree.js b/public/javascripts/note_tree.js
index a07101b064..f1dd5ebddc 100644
--- a/public/javascripts/note_tree.js
+++ b/public/javascripts/note_tree.js
@@ -64,17 +64,33 @@ const noteTree = (function() {
const noteId = getCurrentNoteId();
if (noteId) {
- return getNodes(noteId);
+ return getNodesByNoteId(noteId);
}
else {
return [];
}
}
- function getNodes(noteId) {
+ function getNodesByNoteTreeId(noteTreeId) {
+ const noteTree = notesTreeMap[noteTreeId];
+
+ return getNodesByNoteId(noteTree.note_id).filter(node => node.data.note_tree_id === noteTreeId);
+ }
+
+ function getNodesByNoteId(noteId) {
return getTree().getNodesByRef(noteId);
}
+ function setPrefix(noteTreeId, prefix) {
+ notesTreeMap[noteTreeId].prefix = prefix;
+
+ getNodesByNoteTreeId(noteTreeId).map(node => {
+ node.data.prefix = prefix;
+
+ treeUtils.setNodeTitleWithPrefix(node);
+ });
+ }
+
function prepareNoteTree(notes) {
parentToChildren = {};
childToParents = {};
@@ -218,7 +234,7 @@ const noteTree = (function() {
let parentNoteId = 'root';
for (const childNoteId of runPath) {
- const node = getNodes(childNoteId).find(node => node.data.note_pid === parentNoteId);
+ const node = getNodesByNoteId(childNoteId).find(node => node.data.note_pid === parentNoteId);
if (childNoteId === noteId) {
await node.setActive();
@@ -348,7 +364,7 @@ const noteTree = (function() {
}
},
"f2": node => {
- editTreePrefix.showDialog();
+ editTreePrefix.showDialog(node);
}
};
@@ -548,11 +564,7 @@ const noteTree = (function() {
if (currentNoteId) {
noteIdToTitle[currentNoteId] = title;
- getCurrentClones().map(clone => {
- const fullTitle = (clone.data.prefix ? (clone.data.prefix + " - ") : "") + title;
-
- clone.setTitle(fullTitle)
- });
+ getNodesByNoteId(currentNoteId).map(clone => treeUtils.setNodeTitleWithPrefix(clone));
}
}
@@ -628,6 +640,8 @@ const noteTree = (function() {
getAutocompleteItems,
setCurrentNoteTitle,
createNewTopLevelNote,
- createNote
+ createNote,
+ setPrefix,
+ getNodesByNoteTreeId
};
})();
\ No newline at end of file
diff --git a/public/javascripts/tree_utils.js b/public/javascripts/tree_utils.js
index d580f89753..247320195f 100644
--- a/public/javascripts/tree_utils.js
+++ b/public/javascripts/tree_utils.js
@@ -38,11 +38,21 @@ const treeUtils = (function() {
return path.reverse().join("/");
}
+ function setNodeTitleWithPrefix(node) {
+ const noteTitle = noteTree.getNoteTitle(node.data.note_id);
+ const prefix = node.data.prefix;
+
+ const title = (prefix ? (prefix + " - ") : "") + noteTitle;
+
+ node.setTitle(title);
+ }
+
return {
getParentProtectedStatus,
getNodeByKey,
getFullNameForPath,
getNotePath,
- getNoteIdFromNotePath
+ getNoteIdFromNotePath,
+ setNodeTitleWithPrefix
};
})();
\ No newline at end of file