mirror of
				https://github.com/TriliumNext/Notes.git
				synced 2025-10-31 13:01:31 +08:00 
			
		
		
		
	fixes to note loading. Sidebar flickers way less after note change
This commit is contained in:
		
							parent
							
								
									a17b8a053e
								
							
						
					
					
						commit
						135102d2b5
					
				| @ -268,6 +268,10 @@ class Attributes { | |||||||
|     } |     } | ||||||
| 
 | 
 | ||||||
|     eventReceived(name, data) { |     eventReceived(name, data) { | ||||||
|  |         if (!this.ctx.note) { | ||||||
|  |             return; | ||||||
|  |         } | ||||||
|  | 
 | ||||||
|         if (name === 'syncData') { |         if (name === 'syncData') { | ||||||
|             if (data.find(sd => sd.entityName === 'attributes' && sd.noteId === this.ctx.note.noteId)) { |             if (data.find(sd => sd.entityName === 'attributes' && sd.noteId === this.ctx.note.noteId)) { | ||||||
|                 this.reloadAttributes(); |                 this.reloadAttributes(); | ||||||
|  | |||||||
| @ -374,20 +374,11 @@ tabRow.addListener('activeTabChange', async ({ detail }) => { | |||||||
| tabRow.addListener('tabRemove', async ({ detail }) => { | tabRow.addListener('tabRemove', async ({ detail }) => { | ||||||
|     const tabId = detail.tabEl.getAttribute('data-tab-id'); |     const tabId = detail.tabEl.getAttribute('data-tab-id'); | ||||||
| 
 | 
 | ||||||
|     const tabContextToDelete = tabContexts.find(nc => nc.tabId === tabId); |     tabContexts.filter(nc => nc.tabId === tabId) | ||||||
| 
 |         .forEach(tc => tc.remove()); | ||||||
|     if (tabContextToDelete) { |  | ||||||
|         // sometimes there are orphan autocompletes after closing the tab
 |  | ||||||
|         tabContextToDelete.closeAutocomplete(); |  | ||||||
| 
 |  | ||||||
|         await tabContextToDelete.saveNoteIfChanged(); |  | ||||||
|         tabContextToDelete.$tabContent.remove(); |  | ||||||
|     } |  | ||||||
| 
 | 
 | ||||||
|     tabContexts = tabContexts.filter(nc => nc.tabId !== tabId); |     tabContexts = tabContexts.filter(nc => nc.tabId !== tabId); | ||||||
| 
 | 
 | ||||||
|     console.log(`Removed tab ${tabId}`); |  | ||||||
| 
 |  | ||||||
|     if (tabContexts.length === 0) { |     if (tabContexts.length === 0) { | ||||||
|         openEmptyTab(); |         openEmptyTab(); | ||||||
|     } |     } | ||||||
|  | |||||||
| @ -59,7 +59,6 @@ class Sidebar { | |||||||
|         } |         } | ||||||
| 
 | 
 | ||||||
|         this.widgets = []; |         this.widgets = []; | ||||||
|         this.$widgetContainer.empty(); |  | ||||||
| 
 | 
 | ||||||
|         const widgetClasses = (await Promise.all([ |         const widgetClasses = (await Promise.all([ | ||||||
|             import("../widgets/note_info.js"), |             import("../widgets/note_info.js"), | ||||||
| @ -95,15 +94,19 @@ class Sidebar { | |||||||
| 
 | 
 | ||||||
|         this.widgets.sort((a, b) => a.getPosition() < b.getPosition() ? -1 : 1); |         this.widgets.sort((a, b) => a.getPosition() < b.getPosition() ? -1 : 1); | ||||||
| 
 | 
 | ||||||
|  |         const widgetsToAppend = []; | ||||||
|  | 
 | ||||||
|         for (const widget of this.widgets) { |         for (const widget of this.widgets) { | ||||||
|             try { |             try { | ||||||
|                 const $el = await widget.render(); |                 const $el = await widget.render(); | ||||||
|                 this.$widgetContainer.append($el); |                 widgetsToAppend.push($el); | ||||||
|             } |             } | ||||||
|             catch (e) { |             catch (e) { | ||||||
|                 ws.logError(`Error while rendering widget ${widget.widgetName}: ${e.message}`); |                 ws.logError(`Error while rendering widget ${widget.widgetName}: ${e.message}`); | ||||||
|             } |             } | ||||||
|         } |         } | ||||||
|  | 
 | ||||||
|  |         this.$widgetContainer.empty().append(...widgetsToAppend); | ||||||
|     } |     } | ||||||
| 
 | 
 | ||||||
|     eventReceived(name, data) { |     eventReceived(name, data) { | ||||||
|  | |||||||
| @ -112,6 +112,10 @@ class TabContext { | |||||||
|         this.$unprotectButton = this.$tabContent.find(".unprotect-button"); |         this.$unprotectButton = this.$tabContent.find(".unprotect-button"); | ||||||
|         this.$unprotectButton.click(protectedSessionService.unprotectNoteAndSendToServer); |         this.$unprotectButton.click(protectedSessionService.unprotectNoteAndSendToServer); | ||||||
| 
 | 
 | ||||||
|  |         await this.initComponent(); | ||||||
|  |     } | ||||||
|  | 
 | ||||||
|  |     async initComponent() { | ||||||
|         const type = this.getComponentType(); |         const type = this.getComponentType(); | ||||||
| 
 | 
 | ||||||
|         if (!(type in this.components)) { |         if (!(type in this.components)) { | ||||||
| @ -122,19 +126,15 @@ class TabContext { | |||||||
|     } |     } | ||||||
| 
 | 
 | ||||||
|     async setNote(note, notePath) { |     async setNote(note, notePath) { | ||||||
|         this.noteId = note.noteId; |  | ||||||
|         this.notePath = notePath; |  | ||||||
|         /** @property {NoteFull} */ |         /** @property {NoteFull} */ | ||||||
|         this.note = note; |         this.note = note; | ||||||
|         this.tabRow.updateTab(this.$tab[0], {title: note.title}); |         this.notePath = notePath; | ||||||
|  |         this.tabRow.updateTab(this.$tab[0], {title: this.note.title}); | ||||||
| 
 | 
 | ||||||
|         if (!this.initialized) { |         if (!this.initialized) { | ||||||
|             return; |             return; | ||||||
|         } |         } | ||||||
| 
 | 
 | ||||||
|         // after loading new note make sure editor is scrolled to the top
 |  | ||||||
|         this.getComponent().scrollToTop(); |  | ||||||
| 
 |  | ||||||
|         this.setupClasses(); |         this.setupClasses(); | ||||||
| 
 | 
 | ||||||
|         this.setCurrentNotePathToHash(); |         this.setCurrentNotePathToHash(); | ||||||
| @ -149,6 +149,9 @@ class TabContext { | |||||||
|             this.noteChangeDisabled = false; |             this.noteChangeDisabled = false; | ||||||
|         } |         } | ||||||
| 
 | 
 | ||||||
|  |         // after loading new note make sure editor is scrolled to the top
 | ||||||
|  |         this.getComponent().scrollToTop(); | ||||||
|  | 
 | ||||||
|         this.setTitleBar(); |         this.setTitleBar(); | ||||||
| 
 | 
 | ||||||
|         this.closeAutocomplete(); // esp. on windows autocomplete is not getting closed automatically
 |         this.closeAutocomplete(); // esp. on windows autocomplete is not getting closed automatically
 | ||||||
| @ -157,7 +160,7 @@ class TabContext { | |||||||
|             // we include the note into recent list only if the user stayed on the note at least 5 seconds
 |             // we include the note into recent list only if the user stayed on the note at least 5 seconds
 | ||||||
|             if (notePath && notePath === this.notePath) { |             if (notePath && notePath === this.notePath) { | ||||||
|                 await server.post('recent-notes', { |                 await server.post('recent-notes', { | ||||||
|                     noteId: this.noteId, |                     noteId: this.note.noteId, | ||||||
|                     notePath: this.notePath |                     notePath: this.notePath | ||||||
|                 }); |                 }); | ||||||
|             } |             } | ||||||
| @ -192,6 +195,9 @@ class TabContext { | |||||||
|             if (this.note) { |             if (this.note) { | ||||||
|                 await this.setNote(this.note, this.notePath); |                 await this.setNote(this.note, this.notePath); | ||||||
|             } |             } | ||||||
|  |             else { | ||||||
|  |                 await this.renderComponent(); // render empty page
 | ||||||
|  |             } | ||||||
|         } |         } | ||||||
| 
 | 
 | ||||||
|         this.$tabContent.show(); |         this.$tabContent.show(); | ||||||
| @ -201,6 +207,8 @@ class TabContext { | |||||||
|     } |     } | ||||||
| 
 | 
 | ||||||
|     async renderComponent() { |     async renderComponent() { | ||||||
|  |         await this.initComponent() | ||||||
|  | 
 | ||||||
|         for (const componentType in this.components) { |         for (const componentType in this.components) { | ||||||
|             if (componentType !== this.getComponentType()) { |             if (componentType !== this.getComponentType()) { | ||||||
|                 this.components[componentType].cleanup(); |                 this.components[componentType].cleanup(); | ||||||
| @ -426,6 +434,14 @@ class TabContext { | |||||||
|         } |         } | ||||||
|     } |     } | ||||||
| 
 | 
 | ||||||
|  |     async remove() { | ||||||
|  |         // sometimes there are orphan autocompletes after closing the tab
 | ||||||
|  |         this.closeAutocomplete(); | ||||||
|  | 
 | ||||||
|  |         await this.saveNoteIfChanged(); | ||||||
|  |         this.$tabContent.remove(); | ||||||
|  |     } | ||||||
|  | 
 | ||||||
|     closeAutocomplete() { |     closeAutocomplete() { | ||||||
|         if (utils.isDesktop()) { |         if (utils.isDesktop()) { | ||||||
|             this.$tabContent.find('.aa-input').autocomplete('close'); |             this.$tabContent.find('.aa-input').autocomplete('close'); | ||||||
|  | |||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user
	 zadam
						zadam