mirror of
				https://github.com/zadam/trilium.git
				synced 2025-10-31 03:29:02 +01:00 
			
		
		
		
	Merge pull request #4001 from dymani/reopen-in-place
Reopen recently closed tab/split in place
This commit is contained in:
		
						commit
						0599891ec0
					
				| @ -20,7 +20,7 @@ export default class TabManager extends Component { | |||||||
| 
 | 
 | ||||||
|         this.activeNtxId = null; |         this.activeNtxId = null; | ||||||
| 
 | 
 | ||||||
|         // elements are arrays of note contexts for each tab (one main context + subcontexts [splits])
 |         // elements are arrays of {contexts, position}, storing note contexts for each tab (one main context + subcontexts [splits]), and the original position of the tab
 | ||||||
|         this.recentlyClosedTabs = []; |         this.recentlyClosedTabs = []; | ||||||
| 
 | 
 | ||||||
|         this.tabsUpdate = new SpacedUpdate(async () => { |         this.tabsUpdate = new SpacedUpdate(async () => { | ||||||
| @ -448,21 +448,23 @@ export default class TabManager extends Component { | |||||||
|     removeNoteContexts(noteContextsToRemove) { |     removeNoteContexts(noteContextsToRemove) { | ||||||
|         const ntxIdsToRemove = noteContextsToRemove.map(nc => nc.ntxId); |         const ntxIdsToRemove = noteContextsToRemove.map(nc => nc.ntxId); | ||||||
| 
 | 
 | ||||||
|  |         const position = this.noteContexts.findIndex(nc => ntxIdsToRemove.includes(nc.ntxId)); | ||||||
|  | 
 | ||||||
|         this.children = this.children.filter(nc => !ntxIdsToRemove.includes(nc.ntxId)); |         this.children = this.children.filter(nc => !ntxIdsToRemove.includes(nc.ntxId)); | ||||||
| 
 | 
 | ||||||
|         this.addToRecentlyClosedTabs(noteContextsToRemove); |         this.addToRecentlyClosedTabs(noteContextsToRemove, position); | ||||||
| 
 | 
 | ||||||
|         this.triggerEvent('noteContextRemoved', {ntxIds: ntxIdsToRemove}); |         this.triggerEvent('noteContextRemoved', {ntxIds: ntxIdsToRemove}); | ||||||
| 
 | 
 | ||||||
|         this.tabsUpdate.scheduleUpdate(); |         this.tabsUpdate.scheduleUpdate(); | ||||||
|     } |     } | ||||||
| 
 | 
 | ||||||
|     addToRecentlyClosedTabs(noteContexts) { |     addToRecentlyClosedTabs(noteContexts, position) { | ||||||
|         if (noteContexts.length === 1 && noteContexts[0].isEmpty()) { |         if (noteContexts.length === 1 && noteContexts[0].isEmpty()) { | ||||||
|             return; |             return; | ||||||
|         } |         } | ||||||
| 
 | 
 | ||||||
|         this.recentlyClosedTabs.push(noteContexts); |         this.recentlyClosedTabs.push({contexts: noteContexts, position: position}); | ||||||
|     } |     } | ||||||
| 
 | 
 | ||||||
|     tabReorderEvent({ntxIdsInOrder}) { |     tabReorderEvent({ntxIdsInOrder}) { | ||||||
| @ -574,7 +576,8 @@ export default class TabManager extends Component { | |||||||
|                 closeLastEmptyTab = this.noteContexts[0]; |                 closeLastEmptyTab = this.noteContexts[0]; | ||||||
|             } |             } | ||||||
| 
 | 
 | ||||||
|             const noteContexts = this.recentlyClosedTabs.pop(); |             const lastClosedTab = this.recentlyClosedTabs.pop(); | ||||||
|  |             const noteContexts = lastClosedTab.contexts; | ||||||
| 
 | 
 | ||||||
|             for (const noteContext of noteContexts) { |             for (const noteContext of noteContexts) { | ||||||
|                 this.child(noteContext); |                 this.child(noteContext); | ||||||
| @ -582,6 +585,30 @@ export default class TabManager extends Component { | |||||||
|                 await this.triggerEvent('newNoteContextCreated', {noteContext}); |                 await this.triggerEvent('newNoteContextCreated', {noteContext}); | ||||||
|             } |             } | ||||||
| 
 | 
 | ||||||
|  |             //  restore last position of contexts stored in tab manager
 | ||||||
|  |             const ntxsInOrder = [ | ||||||
|  |                 ...this.noteContexts.slice(0, lastClosedTab.position), | ||||||
|  |                 ...this.noteContexts.slice(-noteContexts.length), | ||||||
|  |                 ...this.noteContexts.slice(lastClosedTab.position, -noteContexts.length), | ||||||
|  |             ] | ||||||
|  |             await this.noteContextReorderEvent({ntxIdsInOrder: ntxsInOrder.map(nc => nc.ntxId)}); | ||||||
|  | 
 | ||||||
|  |             let mainNtx = noteContexts.find(nc => nc.isMainContext()); | ||||||
|  |             if (mainNtx) { | ||||||
|  |                 // reopened a tab, need to reorder new tab widget in tab row
 | ||||||
|  |                 await this.triggerEvent('contextsReopened', { | ||||||
|  |                     mainNtxId: mainNtx.ntxId, | ||||||
|  |                     tabPosition: ntxsInOrder.filter(nc => nc.isMainContext()).findIndex(nc => nc.ntxId === mainNtx.ntxId) | ||||||
|  |                 }); | ||||||
|  |             } else { | ||||||
|  |                 // reopened a single split, need to reorder the pane widget in split note container
 | ||||||
|  |                 await this.triggerEvent('contextsReopened', { | ||||||
|  |                     ntxId: ntxsInOrder[lastClosedTab.position].ntxId, | ||||||
|  |                     // this is safe since lastClosedTab.position can never be 0 in this case
 | ||||||
|  |                     afterNtxId: ntxsInOrder[lastClosedTab.position - 1].ntxId | ||||||
|  |                 }); | ||||||
|  |             } | ||||||
|  | 
 | ||||||
|             const noteContextToActivate = noteContexts.length === 1 |             const noteContextToActivate = noteContexts.length === 1 | ||||||
|                 ? noteContexts[0] |                 ? noteContexts[0] | ||||||
|                 : noteContexts.find(nc => nc.isMainContext()); |                 : noteContexts.find(nc => nc.isMainContext()); | ||||||
|  | |||||||
| @ -44,4 +44,8 @@ export default class MovePaneButton extends OnClickButtonWidget { | |||||||
|     async noteContextReorderEvent() { |     async noteContextReorderEvent() { | ||||||
|         this.refresh(); |         this.refresh(); | ||||||
|     } |     } | ||||||
|  | 
 | ||||||
|  |     async contextsReopenedEvent() { | ||||||
|  |         this.refresh(); | ||||||
|  |     } | ||||||
| } | } | ||||||
|  | |||||||
| @ -136,6 +136,15 @@ export default class SplitNoteContainer extends FlexContainer { | |||||||
|         } |         } | ||||||
|     } |     } | ||||||
| 
 | 
 | ||||||
|  |     contextsReopenedEvent({ntxId, afterNtxId}) { | ||||||
|  |         if (ntxId === undefined || afterNtxId === undefined) { | ||||||
|  |             // no single split reopened
 | ||||||
|  |             return; | ||||||
|  |         } | ||||||
|  |         this.$widget.find(`[data-ntx-id="${ntxId}"]`) | ||||||
|  |             .insertAfter(this.$widget.find(`[data-ntx-id="${afterNtxId}"]`)); | ||||||
|  |     } | ||||||
|  | 
 | ||||||
|     async refresh() { |     async refresh() { | ||||||
|         this.toggleExt(true); |         this.toggleExt(true); | ||||||
|     } |     } | ||||||
|  | |||||||
| @ -620,6 +620,15 @@ export default class TabRowWidget extends BasicWidget { | |||||||
|         this.updateTabById(newMainNtxId);         |         this.updateTabById(newMainNtxId);         | ||||||
|     } |     } | ||||||
| 
 | 
 | ||||||
|  |     contextsReopenedEvent({mainNtxId, tabPosition}) { | ||||||
|  |         if (mainNtxId === undefined || tabPosition === undefined) { | ||||||
|  |             // no tab reopened
 | ||||||
|  |             return; | ||||||
|  |         } | ||||||
|  |         const tabEl = this.getTabById(mainNtxId)[0]; | ||||||
|  |         tabEl.parentNode.insertBefore(tabEl, this.tabEls[tabPosition]); | ||||||
|  |     } | ||||||
|  | 
 | ||||||
|     updateTabById(ntxId) { |     updateTabById(ntxId) { | ||||||
|         const $tab = this.getTabById(ntxId); |         const $tab = this.getTabById(ntxId); | ||||||
| 
 | 
 | ||||||
|  | |||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user
	 zadam
						zadam