mirror of
				https://github.com/zadam/trilium.git
				synced 2025-10-31 02:16:05 +01:00 
			
		
		
		
	add 200ms timeout to api.getTextEditor() and similar #4174
This commit is contained in:
		| @@ -265,32 +265,39 @@ class NoteContext extends Component { | |||||||
|     } |     } | ||||||
|  |  | ||||||
|     async getTextEditor(callback) { |     async getTextEditor(callback) { | ||||||
|         return new Promise(resolve => appContext.triggerCommand('executeWithTextEditor', { |         return this.timeout(new Promise(resolve => appContext.triggerCommand('executeWithTextEditor', { | ||||||
|             callback, |             callback, | ||||||
|             resolve, |             resolve, | ||||||
|             ntxId: this.ntxId |             ntxId: this.ntxId | ||||||
|         })); |         }))); | ||||||
|     } |     } | ||||||
|  |  | ||||||
|     async getCodeEditor() { |     async getCodeEditor() { | ||||||
|         return new Promise(resolve => appContext.triggerCommand('executeWithCodeEditor', { |         return this.timeout(new Promise(resolve => appContext.triggerCommand('executeWithCodeEditor', { | ||||||
|             resolve, |             resolve, | ||||||
|             ntxId: this.ntxId |             ntxId: this.ntxId | ||||||
|         })); |         }))); | ||||||
|     } |     } | ||||||
|  |  | ||||||
|     async getContentElement() { |     async getContentElement() { | ||||||
|         return new Promise(resolve => appContext.triggerCommand('executeWithContentElement', { |         return this.timeout(new Promise(resolve => appContext.triggerCommand('executeWithContentElement', { | ||||||
|             resolve, |             resolve, | ||||||
|             ntxId: this.ntxId |             ntxId: this.ntxId | ||||||
|         })); |         }))); | ||||||
|     } |     } | ||||||
|  |  | ||||||
|     async getTypeWidget() { |     async getTypeWidget() { | ||||||
|         return new Promise(resolve => appContext.triggerCommand('executeWithTypeWidget', { |         return this.timeout(new Promise(resolve => appContext.triggerCommand('executeWithTypeWidget', { | ||||||
|             resolve, |             resolve, | ||||||
|             ntxId: this.ntxId |             ntxId: this.ntxId | ||||||
|         })); |         }))); | ||||||
|  |     } | ||||||
|  |  | ||||||
|  |     timeout(promise) { | ||||||
|  |         return Promise.race([ | ||||||
|  |             promise, | ||||||
|  |             new Promise(res => setTimeout(() => res(null), 200)) | ||||||
|  |         ]); | ||||||
|     } |     } | ||||||
|  |  | ||||||
|     resetViewScope() { |     resetViewScope() { | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user