mirror of
				https://github.com/TriliumNext/Notes.git
				synced 2025-10-31 13:01:31 +08:00 
			
		
		
		
	fix reopening the very last tab, closes #3397
This commit is contained in:
		
							parent
							
								
									c44bc60667
								
							
						
					
					
						commit
						494f8d2153
					
				| @ -32,6 +32,10 @@ class NoteContext extends Component { | |||||||
|         }); |         }); | ||||||
|     } |     } | ||||||
| 
 | 
 | ||||||
|  |     isEmpty() { | ||||||
|  |         return !this.noteId; | ||||||
|  |     } | ||||||
|  | 
 | ||||||
|     async setNote(inputNotePath, triggerSwitchEvent = true) { |     async setNote(inputNotePath, triggerSwitchEvent = true) { | ||||||
|         const resolvedNotePath = await this.getResolvedNotePath(inputNotePath); |         const resolvedNotePath = await this.getResolvedNotePath(inputNotePath); | ||||||
| 
 | 
 | ||||||
| @ -59,8 +63,6 @@ class NoteContext extends Component { | |||||||
|             }); |             }); | ||||||
|         } |         } | ||||||
| 
 | 
 | ||||||
|         console.log(resolvedNotePath, "resolvedNotePath"); |  | ||||||
| 
 |  | ||||||
|         if (this.hoistedNoteId === 'root' && this.notePath.startsWith("root/hidden")) { |         if (this.hoistedNoteId === 'root' && this.notePath.startsWith("root/hidden")) { | ||||||
|             // hidden subtree displays only when hoisted so it doesn't make sense to keep root as hoisted note
 |             // hidden subtree displays only when hoisted so it doesn't make sense to keep root as hoisted note
 | ||||||
| 
 | 
 | ||||||
|  | |||||||
| @ -324,15 +324,17 @@ export default class TabManager extends Component { | |||||||
|             } |             } | ||||||
| 
 | 
 | ||||||
|             if (noteContextToRemove.isMainContext()) { |             if (noteContextToRemove.isMainContext()) { | ||||||
|                 // forbid removing last main note context
 |  | ||||||
|                 // this was previously allowed (was replaced with empty tab) but this proved to be prone to race conditions
 |  | ||||||
|                 const mainNoteContexts = this.getNoteContexts().filter(nc => nc.isMainContext()); |                 const mainNoteContexts = this.getNoteContexts().filter(nc => nc.isMainContext()); | ||||||
| 
 | 
 | ||||||
|                 if (mainNoteContexts.length === 1) { |                 if (mainNoteContexts.length === 1) { | ||||||
|                     await this.clearLastMainNoteContext(noteContextToRemove); |                     if (noteContextToRemove.isEmpty()) { | ||||||
| 
 |                         // this is already the empty note context, no point in closing it and replacing with another
 | ||||||
|  |                         // empty tab
 | ||||||
|                         return false; |                         return false; | ||||||
|                     } |                     } | ||||||
|  | 
 | ||||||
|  |                     await this.openEmptyTab(); | ||||||
|  |                 } | ||||||
|             } |             } | ||||||
| 
 | 
 | ||||||
|             // close dangling autocompletes after closing the tab
 |             // close dangling autocompletes after closing the tab
 | ||||||
| @ -366,35 +368,26 @@ export default class TabManager extends Component { | |||||||
|         }); |         }); | ||||||
|     } |     } | ||||||
| 
 | 
 | ||||||
|     async clearLastMainNoteContext(noteContextToClear) { |  | ||||||
|         noteContextToClear.setEmpty(); |  | ||||||
| 
 |  | ||||||
|         // activate main split
 |  | ||||||
|         await this.activateNoteContext(noteContextToClear.ntxId); |  | ||||||
| 
 |  | ||||||
|         // remove all other splits
 |  | ||||||
|         const noteContextsToRemove = noteContextToClear.getSubContexts() |  | ||||||
|             .filter(ntx => ntx.ntxId !== noteContextToClear.ntxId); |  | ||||||
| 
 |  | ||||||
|         const ntxIdsToRemove = noteContextsToRemove.map(ntx => ntx.ntxId); |  | ||||||
| 
 |  | ||||||
|         await this.triggerEvent('beforeNoteContextRemove', {ntxIds: ntxIdsToRemove}); |  | ||||||
| 
 |  | ||||||
|         this.removeNoteContexts(noteContextsToRemove); |  | ||||||
|     } |  | ||||||
| 
 |  | ||||||
|     removeNoteContexts(noteContextsToRemove) { |     removeNoteContexts(noteContextsToRemove) { | ||||||
|         const ntxIdsToRemove = noteContextsToRemove.map(nc => nc.ntxId); |         const ntxIdsToRemove = noteContextsToRemove.map(nc => nc.ntxId); | ||||||
| 
 | 
 | ||||||
|         this.children = this.children.filter(nc => !ntxIdsToRemove.includes(nc.ntxId)); |         this.children = this.children.filter(nc => !ntxIdsToRemove.includes(nc.ntxId)); | ||||||
| 
 | 
 | ||||||
|         this.recentlyClosedTabs.push(noteContextsToRemove); |         this.addToRecentlyClosedTabs(noteContextsToRemove); | ||||||
| 
 | 
 | ||||||
|         this.triggerEvent('noteContextRemoved', {ntxIds: ntxIdsToRemove}); |         this.triggerEvent('noteContextRemoved', {ntxIds: ntxIdsToRemove}); | ||||||
| 
 | 
 | ||||||
|         this.tabsUpdate.scheduleUpdate(); |         this.tabsUpdate.scheduleUpdate(); | ||||||
|     } |     } | ||||||
| 
 | 
 | ||||||
|  |     addToRecentlyClosedTabs(noteContexts) { | ||||||
|  |         if (noteContexts.length === 1 && noteContexts[0].isEmpty()) { | ||||||
|  |             return; | ||||||
|  |         } | ||||||
|  | 
 | ||||||
|  |         this.recentlyClosedTabs.push(noteContexts);console.log(this.recentlyClosedTabs); | ||||||
|  |     } | ||||||
|  | 
 | ||||||
|     tabReorderEvent({ntxIdsInOrder}) { |     tabReorderEvent({ntxIdsInOrder}) { | ||||||
|         const order = {}; |         const order = {}; | ||||||
| 
 | 
 | ||||||
| @ -481,7 +474,18 @@ export default class TabManager extends Component { | |||||||
|     } |     } | ||||||
| 
 | 
 | ||||||
|     async reopenLastTabCommand() { |     async reopenLastTabCommand() { | ||||||
|         if (this.recentlyClosedTabs.length > 0) { |         let closeLastEmptyTab = null; | ||||||
|  | 
 | ||||||
|  |         await this.mutex.runExclusively(async () => { | ||||||
|  |             if (this.recentlyClosedTabs.length === 0) { | ||||||
|  |                 return; | ||||||
|  |             } | ||||||
|  | 
 | ||||||
|  |             if (this.noteContexts.length === 1 && this.noteContexts[0].isEmpty()) { | ||||||
|  |                 // new empty tab is created after closing the last tab, this reverses the empty tab creation
 | ||||||
|  |                 closeLastEmptyTab = this.noteContexts[0]; | ||||||
|  |             } | ||||||
|  | 
 | ||||||
|             const noteContexts = this.recentlyClosedTabs.pop(); |             const noteContexts = this.recentlyClosedTabs.pop(); | ||||||
| 
 | 
 | ||||||
|             for (const noteContext of noteContexts) { |             for (const noteContext of noteContexts) { | ||||||
| @ -494,12 +498,16 @@ export default class TabManager extends Component { | |||||||
|                 ? noteContexts[0] |                 ? noteContexts[0] | ||||||
|                 : noteContexts.find(nc => nc.isMainContext()); |                 : noteContexts.find(nc => nc.isMainContext()); | ||||||
| 
 | 
 | ||||||
|             this.activateNoteContext(noteContextToActivate.ntxId); |             await this.activateNoteContext(noteContextToActivate.ntxId); | ||||||
| 
 | 
 | ||||||
|             await this.triggerEvent('noteSwitched', { |             await this.triggerEvent('noteSwitched', { | ||||||
|                 noteContext: noteContextToActivate, |                 noteContext: noteContextToActivate, | ||||||
|                 notePath: noteContextToActivate.notePath |                 notePath: noteContextToActivate.notePath | ||||||
|             }); |             }); | ||||||
|  |         }); | ||||||
|  | 
 | ||||||
|  |         if (closeLastEmptyTab) { | ||||||
|  |             await this.removeNoteContext(closeLastEmptyTab.ntxId); | ||||||
|         } |         } | ||||||
|     } |     } | ||||||
| 
 | 
 | ||||||
|  | |||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user
	 zadam
						zadam