mirror of
				https://github.com/TriliumNext/Notes.git
				synced 2025-10-31 13:01:31 +08:00 
			
		
		
		
	use notePath instead of noteId for note creation to correctly work with cloned ancestors
This commit is contained in:
		
							parent
							
								
									8192b51b8a
								
							
						
					
					
						commit
						721e5da672
					
				| @ -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, | ||||
|  | ||||
| @ -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`); | ||||
|  | ||||
| @ -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}); | ||||
|         } | ||||
|     } | ||||
|  | ||||
| @ -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 | ||||
|         }); | ||||
|  | ||||
| @ -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(); | ||||
|  | ||||
| @ -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 | ||||
|         }); | ||||
|  | ||||
| @ -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 | ||||
|             }); | ||||
|         }); | ||||
|  | ||||
| @ -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 | ||||
|         }); | ||||
|  | ||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user
	 zadam
						zadam