Build your personal knowledge base with Trilium Notes
TypeScript electronelectron-appknowledge-baseknowledge-graphknowledge-managementknowledge-management-graphlocal-firstnote-managmentnote-takernote-takingnotebooknotesnotes-apppersonal-knowledge-basepersonal-wikiscriptableself-hostedself-hostingwiki
use notePath instead of noteId for note creation to correctly work with cloned ancestors
zadam721e5da67247
diff --git a/src/public/app/services/main_tree_executors.js b/src/public/app/services/main_tree_executors.jsindex fdd5cd1075..d654013780 100644--- a/src/public/app/services/main_tree_executors.js+++ b/src/public/app/services/main_tree_executors.js@@ -27,28 +27,28 @@ export default class MainTreeExecutors extends Component {}async createNoteIntoCommand() {- const activeNote = appContext.tabManager.getActiveTabNote();+ const activeTabContext = appContext.tabManager.getActiveTabContext();- if (!activeNote) {+ if (!activeTabContext) {return;}- await noteCreateService.createNote(activeNote.noteId, {- isProtected: activeNote.isProtected,+ await noteCreateService.createNote(activeTabContext.notePath, {+ isProtected: activeTabContext.note.isProtected,saveSelection: false});}async createNoteAfterCommand() {const node = this.tree.getActiveNode();- const parentNoteId = node.data.parentNoteId;+ const parentNotePath = treeService.getNotePath(node.getParent());const isProtected = await treeService.getParentProtectedStatus(node);if (node.data.noteId === 'root' || node.data.noteId === hoistedNoteService.getHoistedNoteId()) {return;}- await noteCreateService.createNote(parentNoteId, {+ await noteCreateService.createNote(parentNotePath, {target: 'after',targetBranchId: node.data.branchId,isProtected: isProtected,diff --git a/src/public/app/services/note_create.js b/src/public/app/services/note_create.jsindex 8c87ac19ba..063089d584 100644--- a/src/public/app/services/note_create.js+++ b/src/public/app/services/note_create.js@@ -1,13 +1,13 @@-import hoistedNoteService from "./hoisted_note.js";import appContext from "./app_context.js";import utils from "./utils.js";import protectedSessionHolder from "./protected_session_holder.js";import server from "./server.js";import ws from "./ws.js";import treeCache from "./tree_cache.js";+import treeService from "./tree.js";import toastService from "./toast.js";-async function createNote(parentNoteId, options = {}) {+async function createNote(parentNotePath, options = {}) {options = Object.assign({activate: true,focus: 'title',@@ -30,6 +30,8 @@ async function createNote(parentNoteId, options = {}) {const newNoteName = options.title || "new note";+ const parentNoteId = treeService.getNoteIdFromNotePath(parentNotePath);+const {note, branch} = await server.post(`notes/${parentNoteId}/children?target=${options.target}&targetBranchId=${options.targetBranchId}`, {title: newNoteName,content: options.content || "",@@ -47,7 +49,7 @@ async function createNote(parentNoteId, options = {}) {if (options.activate) {const activeTabContext = appContext.tabManager.getActiveTabContext();- await activeTabContext.setNote(note.noteId);+ await activeTabContext.setNote(`${parentNotePath}/${note.noteId}`);if (options.focus === 'title') {appContext.triggerEvent('focusAndSelectTitle');@@ -82,12 +84,13 @@ function parseSelectedHtml(selectedHtml) {}}-async function duplicateSubtree(noteId, parentNoteId) {+async function duplicateSubtree(noteId, parentNotePath) {+ const parentNoteId = treeService.getNoteIdFromNotePath(parentNotePath);const {note} = await server.post(`notes/${noteId}/duplicate/${parentNoteId}`);await ws.waitForMaxKnownEntityChangeId();- await appContext.tabManager.activateOrOpenNote(note.noteId);+ await appContext.tabManager.activateOrOpenNote(`${parentNotePath}/${note.noteId}`);const origNote = await treeCache.getNote(noteId);toastService.showMessage(`Note "${origNote.title}" has been duplicated`);diff --git a/src/public/app/services/tree_context_menu.js b/src/public/app/services/tree_context_menu.jsindex 8d39e9c5bd..92c9989eab 100644--- a/src/public/app/services/tree_context_menu.js+++ b/src/public/app/services/tree_context_menu.js@@ -112,10 +112,10 @@ class TreeContextMenu {appContext.tabManager.openTabWithNoteWithHoisting(notePath);}else if (command === "insertNoteAfter") {- const parentNoteId = this.node.data.parentNoteId;+ const parentNotePath = treeService.getNotePath(this.node.getParent());const isProtected = await treeService.getParentProtectedStatus(this.node);- noteCreateService.createNote(parentNoteId, {+ noteCreateService.createNote(parentNotePath, {target: 'after',targetBranchId: this.node.data.branchId,type: type,@@ -123,14 +123,14 @@ class TreeContextMenu {});}else if (command === "insertChildNote") {- noteCreateService.createNote(noteId, {+ const parentNotePath = treeService.getNotePath(this.node);++ noteCreateService.createNote(parentNotePath, {type: type,isProtected: this.node.data.isProtected});}else {- console.log("Triggering", command, notePath);-this.treeWidget.triggerCommand(command, {node: this.node, notePath: notePath});}}diff --git a/src/public/app/widgets/attribute_widgets/attribute_editor.js b/src/public/app/widgets/attribute_widgets/attribute_editor.jsindex fc88accff0..8c5fe36fe7 100644--- a/src/public/app/widgets/attribute_widgets/attribute_editor.js+++ b/src/public/app/widgets/attribute_widgets/attribute_editor.js@@ -491,7 +491,7 @@ export default class AttributeEditorWidget extends TabAwareWidget {}async createNoteForReferenceLink(title) {- const {note} = await noteCreateService.createNote(this.noteId, {+ const {note} = await noteCreateService.createNote(this.notePath, {activate: false,title: title});diff --git a/src/public/app/widgets/mobile_widgets/mobile_detail_menu.js b/src/public/app/widgets/mobile_widgets/mobile_detail_menu.jsindex eb41682972..4b59cfab13 100644--- a/src/public/app/widgets/mobile_widgets/mobile_detail_menu.js+++ b/src/public/app/widgets/mobile_widgets/mobile_detail_menu.js@@ -26,7 +26,7 @@ class MobileDetailMenuWidget extends BasicWidget {],selectMenuItemHandler: async ({command}) => {if (command === "insertChildNote") {- noteCreateService.createNote(note.noteId);+ noteCreateService.createNote(appContext.tabManager.getActiveTabNotePath());}else if (command === "delete") {const notePath = appContext.tabManager.getActiveTabNotePath();diff --git a/src/public/app/widgets/note_detail.js b/src/public/app/widgets/note_detail.jsindex 42f9877a58..5105c24814 100644--- a/src/public/app/widgets/note_detail.js+++ b/src/public/app/widgets/note_detail.js@@ -318,7 +318,7 @@ export default class NoteDetailWidget extends TabAwareWidget {}// without await as this otherwise causes deadlock through component mutex- noteCreateService.createNote(note.noteId, {+ noteCreateService.createNote(appContext.tabManager.getActiveTabNotePath(), {isProtected: note.isProtected,saveSelection: true});diff --git a/src/public/app/widgets/note_tree.js b/src/public/app/widgets/note_tree.jsindex 4eadc59120..aefc0c2d51 100644--- a/src/public/app/widgets/note_tree.js+++ b/src/public/app/widgets/note_tree.js@@ -203,8 +203,9 @@ export default class NoteTreeWidget extends TabAwareWidget {this.$tree.on("mousedown", ".refresh-search-button", e => this.refreshSearch(e));this.$tree.on("mousedown", ".add-note-button", e => {const node = $.ui.fancytree.getNode(e);+ const parentNotePath = treeService.getNotePath(node);- noteCreateService.createNote(node.data.noteId, {+ noteCreateService.createNote(parentNotePath, {isProtected: node.data.isProtected});});diff --git a/src/public/app/widgets/type_widgets/editable_text.js b/src/public/app/widgets/type_widgets/editable_text.jsindex f7f33c0797..104fe8d634 100644--- a/src/public/app/widgets/type_widgets/editable_text.js+++ b/src/public/app/widgets/type_widgets/editable_text.js@@ -274,7 +274,7 @@ export default class EditableTextTypeWidget extends AbstractTextTypeWidget {}async createNoteForReferenceLink(title) {- const {note} = await noteCreateService.createNote(this.noteId, {+ const {note} = await noteCreateService.createNote(this.notePath, {activate: false,title: title});