mirror of
				https://github.com/zadam/trilium.git
				synced 2025-10-31 10:26:08 +01:00 
			
		
		
		
	Merge pull request #3837 from soulsands/fix-tree
fix: correct moving active node
This commit is contained in:
		| @@ -673,7 +673,7 @@ export default class NoteTreeWidget extends NoteContextAwareWidget { | ||||
|         return noteList; | ||||
|     } | ||||
|  | ||||
|     updateNode(node) { | ||||
|     async updateNode(node) { | ||||
|         const note = froca.getNoteFromCache(node.data.noteId); | ||||
|         const branch = froca.getBranch(node.data.branchId); | ||||
|  | ||||
| @@ -697,7 +697,7 @@ export default class NoteTreeWidget extends NoteContextAwareWidget { | ||||
|         node.title = utils.escapeHtml(title); | ||||
|  | ||||
|         if (node.isExpanded() !== branch.isExpanded) { | ||||
|             node.setExpanded(branch.isExpanded, {noEvents: true, noAnimation: true}); | ||||
|             await node.setExpanded(branch.isExpanded, {noEvents: true, noAnimation: true}); | ||||
|         } | ||||
|  | ||||
|         node.renderTitle(); | ||||
| @@ -920,7 +920,9 @@ export default class NoteTreeWidget extends NoteContextAwareWidget { | ||||
|                 } | ||||
|  | ||||
|                 if (expand) { | ||||
|                     if (!parentNode.isExpanded()) { | ||||
|                         await parentNode.setExpanded(true, {noAnimation: true}); | ||||
|                     } | ||||
|  | ||||
|                     // although previous line should set the expanded status, it seems to happen asynchronously, | ||||
|                     // so we need to make sure it is set properly before calling updateNode which uses this flag | ||||
| @@ -928,7 +930,7 @@ export default class NoteTreeWidget extends NoteContextAwareWidget { | ||||
|                     branch.isExpanded = true; | ||||
|                 } | ||||
|  | ||||
|                 this.updateNode(parentNode); | ||||
|                 await this.updateNode(parentNode); | ||||
|  | ||||
|                 let foundChildNode = this.findChildNode(parentNode, childNoteId); | ||||
|  | ||||
| @@ -1096,10 +1098,10 @@ export default class NoteTreeWidget extends NoteContextAwareWidget { | ||||
|         const activeNode = this.getActiveNode(); | ||||
|         const activeNodeFocused = activeNode && activeNode.hasFocus(); | ||||
|         const nextNode = activeNode ? (activeNode.getNextSibling() || activeNode.getPrevSibling() || activeNode.getParent()) : null; | ||||
|         const activeNotePath = activeNode ? treeService.getNotePath(activeNode) : null; | ||||
|         let activeNotePath = activeNode ? treeService.getNotePath(activeNode) : null; | ||||
|  | ||||
|         const nextNotePath = nextNode ? treeService.getNotePath(nextNode) : null; | ||||
|         const activeNoteId = activeNode ? activeNode.data.noteId : null; | ||||
|         let activeNoteId = activeNode ? activeNode.data.noteId : null; | ||||
|  | ||||
|         const noteIdsToUpdate = new Set(); | ||||
|         const noteIdsToReload = new Set(); | ||||
| @@ -1142,7 +1144,14 @@ export default class NoteTreeWidget extends NoteContextAwareWidget { | ||||
|             } | ||||
|         } | ||||
|  | ||||
|         for (const ecBranch of loadResults.getBranches()) { | ||||
|         // activeNode is supposed to be moved when we find out activeNode is deleted but not all branches are deleted. save it for fixing activeNodePath after all nodes loaded. | ||||
|         let movedActiveNode = null; | ||||
|         let parentsOfAddedNodes = []; | ||||
|  | ||||
|         const allBranches = loadResults.getBranches(); | ||||
|         const allBranchesDeleted = allBranches.every(branch => !!branch.isDeleted); | ||||
|  | ||||
|         for (const ecBranch of allBranches) { | ||||
|             if (ecBranch.parentNoteId === '_share') { | ||||
|                 // all shared notes have a sign in the tree, even the descendants of shared notes | ||||
|                 noteIdsToReload.add(ecBranch.noteId); | ||||
| @@ -1155,6 +1164,7 @@ export default class NoteTreeWidget extends NoteContextAwareWidget { | ||||
|             for (const node of this.getNodesByBranch(ecBranch)) { | ||||
|                 if (ecBranch.isDeleted) { | ||||
|                     if (node.isActive()) { | ||||
|                         if (allBranchesDeleted) { | ||||
|                             const newActiveNode = node.getNextSibling() | ||||
|                                 || node.getPrevSibling() | ||||
|                                 || node.getParent(); | ||||
| @@ -1162,6 +1172,9 @@ export default class NoteTreeWidget extends NoteContextAwareWidget { | ||||
|                             if (newActiveNode) { | ||||
|                                 newActiveNode.setActive(true, {noEvents: true, noFocus: true}); | ||||
|                             } | ||||
|                         } else { | ||||
|                             movedActiveNode = node; | ||||
|                         } | ||||
|                     } | ||||
|  | ||||
|                     if (node.getParent()) { | ||||
| @@ -1174,12 +1187,13 @@ export default class NoteTreeWidget extends NoteContextAwareWidget { | ||||
|  | ||||
|             if (!ecBranch.isDeleted) { | ||||
|                 for (const parentNode of this.getNodesByNoteId(ecBranch.parentNoteId)) { | ||||
|                     parentsOfAddedNodes.push(parentNode) | ||||
|  | ||||
|                     if (parentNode.isFolder() && !parentNode.isLoaded()) { | ||||
|                         continue; | ||||
|                     } | ||||
|  | ||||
|                     const found = (parentNode.getChildren() || []).find(child => child.data.noteId === ecBranch.noteId); | ||||
|  | ||||
|                     if (!found) { | ||||
|                         // make sure it's loaded | ||||
|                         await froca.getNote(ecBranch.noteId); | ||||
| @@ -1222,7 +1236,18 @@ export default class NoteTreeWidget extends NoteContextAwareWidget { | ||||
|         // for some reason node update cannot be in the batchUpdate() block (node is not re-rendered) | ||||
|         for (const noteId of noteIdsToUpdate) { | ||||
|             for (const node of this.getNodesByNoteId(noteId)) { | ||||
|                 this.updateNode(node); | ||||
|                 await this.updateNode(node); | ||||
|             } | ||||
|         } | ||||
|  | ||||
|         if (movedActiveNode) { | ||||
|             for (const parentNode of parentsOfAddedNodes) { | ||||
|                 const found = (parentNode.getChildren() || []).find(child => child.data.noteId === movedActiveNode.data.noteId); | ||||
|                 if (found) { | ||||
|                     activeNotePath = treeService.getNotePath(found); | ||||
|                     activeNoteId = found.data.noteId; | ||||
|                     break | ||||
|                 } | ||||
|             } | ||||
|         } | ||||
|  | ||||
|   | ||||
		Reference in New Issue
	
	Block a user