mirror of
				https://github.com/zadam/trilium.git
				synced 2025-10-31 18:36:30 +01:00 
			
		
		
		
	fix expand subtree's conflict with auto-lazy loading
This commit is contained in:
		| @@ -222,6 +222,9 @@ export default class NoteTreeWidget extends TabAwareWidget { | |||||||
|             }, |             }, | ||||||
|             // this is done to automatically lazy load all expanded search notes after tree load |             // this is done to automatically lazy load all expanded search notes after tree load | ||||||
|             loadChildren: (event, data) => { |             loadChildren: (event, data) => { | ||||||
|  |                 // semaphore since the conflict when two processes are trying to load the same data | ||||||
|  |                 // breaks the fancytree | ||||||
|  |                 if (!this.tree || !this.tree.autoLoadingDisabled) { | ||||||
|                     data.node.visit((subNode) => { |                     data.node.visit((subNode) => { | ||||||
|                         // Load all lazy/unloaded child nodes |                         // Load all lazy/unloaded child nodes | ||||||
|                         // (which will trigger `loadChildren` recursively) |                         // (which will trigger `loadChildren` recursively) | ||||||
| @@ -230,6 +233,7 @@ export default class NoteTreeWidget extends TabAwareWidget { | |||||||
|                         } |                         } | ||||||
|                     }); |                     }); | ||||||
|                 } |                 } | ||||||
|  |             } | ||||||
|         }); |         }); | ||||||
|  |  | ||||||
|         this.$widget.on('contextmenu', '.fancytree-node', e => { |         this.$widget.on('contextmenu', '.fancytree-node', e => { | ||||||
| @@ -262,7 +266,7 @@ export default class NoteTreeWidget extends TabAwareWidget { | |||||||
|         return notes; |         return notes; | ||||||
|     } |     } | ||||||
|  |  | ||||||
|     expandTree(node = null) { |     async expandTree(node = null) { | ||||||
|         if (!node) { |         if (!node) { | ||||||
|             const hoistedNoteId = hoistedNoteService.getHoistedNoteId(); |             const hoistedNoteId = hoistedNoteService.getHoistedNoteId(); | ||||||
|  |  | ||||||
| @@ -270,11 +274,18 @@ export default class NoteTreeWidget extends TabAwareWidget { | |||||||
|         } |         } | ||||||
|  |  | ||||||
|         this.batchUpdate(async () => { |         this.batchUpdate(async () => { | ||||||
|  |             try { | ||||||
|  |                 this.tree.autoLoadingDisabled = true; | ||||||
|  |  | ||||||
|                 // trick - first force load of the whole subtree and then visit and expand. |                 // trick - first force load of the whole subtree and then visit and expand. | ||||||
|                 // unfortunately the two steps can't be combined |                 // unfortunately the two steps can't be combined | ||||||
|             await node.visitAndLoad(node => {}, true); |                 await node.visitAndLoad(_ => {}, true); | ||||||
|  |  | ||||||
|                 node.visit(node => node.setExpanded(true), true); |                 node.visit(node => node.setExpanded(true), true); | ||||||
|  |             } | ||||||
|  |             finally { | ||||||
|  |                 this.tree.autoLoadingDisabled = false; | ||||||
|  |             } | ||||||
|         }); |         }); | ||||||
|     } |     } | ||||||
|  |  | ||||||
| @@ -478,16 +489,14 @@ export default class NoteTreeWidget extends TabAwareWidget { | |||||||
|     } |     } | ||||||
|  |  | ||||||
|     async batchUpdate(cb) { |     async batchUpdate(cb) { | ||||||
|         let prevUpdate; |  | ||||||
|  |  | ||||||
|         try { |         try { | ||||||
|             // disable rendering during update for increased performance |             // disable rendering during update for increased performance | ||||||
|             prevUpdate = this.tree.enableUpdate(false); |             this.tree.enableUpdate(false); | ||||||
|  |  | ||||||
|             await cb(); |             await cb(); | ||||||
|         } |         } | ||||||
|         finally { |         finally { | ||||||
|             this.tree.enableUpdate(prevUpdate); |             this.tree.enableUpdate(true); | ||||||
|         } |         } | ||||||
|     } |     } | ||||||
|  |  | ||||||
| @@ -782,7 +791,7 @@ export default class NoteTreeWidget extends TabAwareWidget { | |||||||
|         } |         } | ||||||
|     } |     } | ||||||
|  |  | ||||||
|     expandSubtreeCommand({node}) {console.log("HQY!", node); |     expandSubtreeCommand({node}) { | ||||||
|         this.expandTree(node); |         this.expandTree(node); | ||||||
|     } |     } | ||||||
|  |  | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user