mirror of
				https://github.com/zadam/trilium.git
				synced 2025-10-31 18:36:30 +01:00 
			
		
		
		
	fix delete note function just work one time, closes #1101
This commit is contained in:
		| @@ -1,29 +0,0 @@ | |||||||
| export default class Mutex { |  | ||||||
|     constructor() { |  | ||||||
|         this.queue = []; |  | ||||||
|         this.pending = false; |  | ||||||
|     } |  | ||||||
|  |  | ||||||
|     isLocked() { |  | ||||||
|         return this.pending; |  | ||||||
|     } |  | ||||||
|  |  | ||||||
|     acquire() { |  | ||||||
|         const ticket = new Promise(resolve => this.queue.push(resolve)); |  | ||||||
|          |  | ||||||
|         if (!this.pending) { |  | ||||||
|             this.dispatchNext(); |  | ||||||
|         } |  | ||||||
|          |  | ||||||
|         return ticket; |  | ||||||
|     } |  | ||||||
|      |  | ||||||
|     dispatchNext() { |  | ||||||
|         if (this.queue.length > 0) { |  | ||||||
|             this.pending = true; |  | ||||||
|             this.queue.shift()(this.dispatchNext.bind(this)); |  | ||||||
|         } else { |  | ||||||
|             this.pending = false; |  | ||||||
|         } |  | ||||||
|     } |  | ||||||
| } |  | ||||||
| @@ -22,7 +22,7 @@ async function resolveNotePath(notePath) { | |||||||
|  * |  * | ||||||
|  * @return {string[]} |  * @return {string[]} | ||||||
|  */ |  */ | ||||||
| async function getRunPath(notePath) { | async function getRunPath(notePath, logErrors = true) { | ||||||
|     utils.assertArguments(notePath); |     utils.assertArguments(notePath); | ||||||
|  |  | ||||||
|     notePath = notePath.split("-")[0].trim(); |     notePath = notePath.split("-")[0].trim(); | ||||||
| @@ -66,10 +66,14 @@ async function getRunPath(notePath) { | |||||||
|             } |             } | ||||||
|  |  | ||||||
|             if (!parents.some(p => p.noteId === parentNoteId)) { |             if (!parents.some(p => p.noteId === parentNoteId)) { | ||||||
|                 console.debug(utils.now(), "Did not find parent " + parentNoteId + " for child " + childNoteId); |                 if (logErrors) { | ||||||
|  |                     console.log(utils.now(), "Did not find parent " + parentNoteId + " for child " + childNoteId); | ||||||
|  |                 } | ||||||
|  |  | ||||||
|                 if (parents.length > 0) { |                 if (parents.length > 0) { | ||||||
|                     console.debug(utils.now(), "Available parents:", parents); |                     if (logErrors) { | ||||||
|  |                         console.log(utils.now(), "Available parents:", parents); | ||||||
|  |                     } | ||||||
|  |  | ||||||
|                     const someNotePath = await getSomeNotePath(parents[0]); |                     const someNotePath = await getSomeNotePath(parents[0]); | ||||||
|  |  | ||||||
| @@ -86,7 +90,10 @@ async function getRunPath(notePath) { | |||||||
|                     break; |                     break; | ||||||
|                 } |                 } | ||||||
|                 else { |                 else { | ||||||
|                     console.log("No parents so no run path."); |                     if (logErrors) { | ||||||
|  |                         console.log("No parents so no run path."); | ||||||
|  |                     } | ||||||
|  |  | ||||||
|                     return; |                     return; | ||||||
|                 } |                 } | ||||||
|             } |             } | ||||||
|   | |||||||
| @@ -1,13 +1,11 @@ | |||||||
| import utils from '../services/utils.js'; | import utils from '../services/utils.js'; | ||||||
| import Mutex from "../services/mutex.js"; |  | ||||||
|  |  | ||||||
| /** | /** | ||||||
|  * Abstract class for all components in the Trilium's frontend. |  * Abstract class for all components in the Trilium's frontend. | ||||||
|  * |  * | ||||||
|  * Contains also event implementation with following properties: |  * Contains also event implementation with following properties: | ||||||
|  * - event / command distribution is synchronous which among others mean that events are well ordered - event |  * - event / command distribution is synchronous which among others mean that events are well ordered - event | ||||||
|  *   which was sent out first will also be processed first by the component since it was added to the mutex queue |  *   which was sent out first will also be processed first by the component | ||||||
|  *   as the first one |  | ||||||
|  * - execution of the event / command is asynchronous - each component executes the event on its own without regard for |  * - execution of the event / command is asynchronous - each component executes the event on its own without regard for | ||||||
|  *   other components. |  *   other components. | ||||||
|  * - although the execution is async, we are collecting all the promises and therefore it is possible to wait until the |  * - although the execution is async, we are collecting all the promises and therefore it is possible to wait until the | ||||||
| @@ -19,7 +17,6 @@ export default class Component { | |||||||
|         /** @type Component[] */ |         /** @type Component[] */ | ||||||
|         this.children = []; |         this.children = []; | ||||||
|         this.initialized = Promise.resolve(); |         this.initialized = Promise.resolve(); | ||||||
|         this.mutex = new Mutex(); |  | ||||||
|     } |     } | ||||||
|  |  | ||||||
|     setParent(parent) { |     setParent(parent) { | ||||||
| @@ -79,22 +76,8 @@ export default class Component { | |||||||
|             return false; |             return false; | ||||||
|         } |         } | ||||||
|  |  | ||||||
|         let release; |         await fun.call(this, data); | ||||||
|  |  | ||||||
|         try { |         return true; | ||||||
|             if (this.mutex.isLocked()) { |  | ||||||
|                 console.debug("Mutex locked for", this.constructor.name); |  | ||||||
|             } |  | ||||||
|  |  | ||||||
|             release = await this.mutex.acquire(); |  | ||||||
|  |  | ||||||
|             await fun.call(this, data); |  | ||||||
|  |  | ||||||
|             return true; |  | ||||||
|         } finally { |  | ||||||
|             if (release) { |  | ||||||
|                 release(); |  | ||||||
|             } |  | ||||||
|         } |  | ||||||
|     } |     } | ||||||
| } | } | ||||||
|   | |||||||
| @@ -743,17 +743,20 @@ export default class NoteTreeWidget extends TabAwareWidget { | |||||||
|     } |     } | ||||||
|  |  | ||||||
|     /** @return {FancytreeNode} */ |     /** @return {FancytreeNode} */ | ||||||
|     async getNodeFromPath(notePath, expand = false) { |     async getNodeFromPath(notePath, expand = false, logErrors = true) { | ||||||
|         utils.assertArguments(notePath); |         utils.assertArguments(notePath); | ||||||
|  |  | ||||||
|         const hoistedNoteId = hoistedNoteService.getHoistedNoteId(); |         const hoistedNoteId = hoistedNoteService.getHoistedNoteId(); | ||||||
|         /** @var {FancytreeNode} */ |         /** @var {FancytreeNode} */ | ||||||
|         let parentNode = null; |         let parentNode = null; | ||||||
|  |  | ||||||
|         const runPath = await treeService.getRunPath(notePath); |         const runPath = await treeService.getRunPath(notePath, logErrors); | ||||||
|  |  | ||||||
|         if (!runPath) { |         if (!runPath) { | ||||||
|             console.error("Could not find run path for notePath:", notePath); |             if (logErrors) { | ||||||
|  |                 console.error("Could not find run path for notePath:", notePath); | ||||||
|  |             } | ||||||
|  |  | ||||||
|             return; |             return; | ||||||
|         } |         } | ||||||
|  |  | ||||||
| @@ -790,7 +793,10 @@ export default class NoteTreeWidget extends TabAwareWidget { | |||||||
|                     foundChildNode = this.findChildNode(parentNode, childNoteId); |                     foundChildNode = this.findChildNode(parentNode, childNoteId); | ||||||
|  |  | ||||||
|                     if (!foundChildNode) { |                     if (!foundChildNode) { | ||||||
|                         ws.logError(`Can't find node for child node of noteId=${childNoteId} for parent of noteId=${parentNode.data.noteId} and hoistedNoteId=${hoistedNoteId}, requested path is ${notePath}`); |                         if (logErrors) { | ||||||
|  |                             ws.logError(`Can't find node for child node of noteId=${childNoteId} for parent of noteId=${parentNode.data.noteId} and hoistedNoteId=${hoistedNoteId}, requested path is ${notePath}`); | ||||||
|  |                         } | ||||||
|  |  | ||||||
|                         return; |                         return; | ||||||
|                     } |                     } | ||||||
|                 } |                 } | ||||||
| @@ -817,8 +823,8 @@ export default class NoteTreeWidget extends TabAwareWidget { | |||||||
|     } |     } | ||||||
|  |  | ||||||
|     /** @return {FancytreeNode} */ |     /** @return {FancytreeNode} */ | ||||||
|     async expandToNote(notePath) { |     async expandToNote(notePath, logErrors = true) { | ||||||
|         return this.getNodeFromPath(notePath, true); |         return this.getNodeFromPath(notePath, true, logErrors); | ||||||
|     } |     } | ||||||
|  |  | ||||||
|     updateNode(node) { |     updateNode(node) { | ||||||
| @@ -1026,7 +1032,7 @@ export default class NoteTreeWidget extends TabAwareWidget { | |||||||
|         } |         } | ||||||
|  |  | ||||||
|         if (activeNotePath) { |         if (activeNotePath) { | ||||||
|             let node = await this.expandToNote(activeNotePath); |             let node = await this.expandToNote(activeNotePath, false); | ||||||
|  |  | ||||||
|             if (node && node.data.noteId !== activeNoteId) { |             if (node && node.data.noteId !== activeNoteId) { | ||||||
|                 // if the active note has been moved elsewhere then it won't be found by the path |                 // if the active note has been moved elsewhere then it won't be found by the path | ||||||
| @@ -1042,7 +1048,7 @@ export default class NoteTreeWidget extends TabAwareWidget { | |||||||
|             } |             } | ||||||
|             else { |             else { | ||||||
|                 // this is used when original note has been deleted and we want to move the focus to the note above/below |                 // this is used when original note has been deleted and we want to move the focus to the note above/below | ||||||
|                 node = await this.expandToNote(nextNotePath); |                 node = await this.expandToNote(nextNotePath, false); | ||||||
|  |  | ||||||
|                 if (node) { |                 if (node) { | ||||||
|                     await appContext.tabManager.getActiveTabContext().setNote(nextNotePath); |                     await appContext.tabManager.getActiveTabContext().setNote(nextNotePath); | ||||||
|   | |||||||
| @@ -68,6 +68,8 @@ | |||||||
|  |  | ||||||
| .note-detail-image { | .note-detail-image { | ||||||
|     text-align: center; |     text-align: center; | ||||||
|  |     height: 100%; | ||||||
|  |     overflow: auto; | ||||||
| } | } | ||||||
|  |  | ||||||
| .note-detail-image-view { | .note-detail-image-view { | ||||||
| @@ -92,4 +94,4 @@ | |||||||
|     max-height: 300px; |     max-height: 300px; | ||||||
|     overflow: auto; |     overflow: auto; | ||||||
|     margin: 10px; |     margin: 10px; | ||||||
| } | } | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user