From 15a9ff44500da3d52f489d8823320d1c49dbaaa8 Mon Sep 17 00:00:00 2001 From: zadam Date: Thu, 2 Jun 2022 22:28:25 +0200 Subject: [PATCH] when closing / clearing last tab, close all splits --- src/public/app/services/tab_manager.js | 42 ++++++++++++++++++++------ src/public/app/widgets/note_detail.js | 2 +- src/public/app/widgets/note_title.js | 2 +- 3 files changed, 35 insertions(+), 11 deletions(-) diff --git a/src/public/app/services/tab_manager.js b/src/public/app/services/tab_manager.js index 15f939bfe..59318d6e3 100644 --- a/src/public/app/services/tab_manager.js +++ b/src/public/app/services/tab_manager.js @@ -306,7 +306,8 @@ export default class TabManager extends Component { const mainNoteContexts = this.getNoteContexts().filter(nc => nc.isMainContext()); if (mainNoteContexts.length === 1) { - mainNoteContexts[0].setEmpty(); + await this.clearLastMainNoteContext(noteContextToRemove); + return; } } @@ -317,7 +318,7 @@ export default class TabManager extends Component { const noteContextsToRemove = noteContextToRemove.getSubContexts(); const ntxIdsToRemove = noteContextsToRemove.map(nc => nc.ntxId); - await this.triggerEvent('beforeTabRemove', { ntxIds: ntxIdsToRemove }); + await this.triggerEvent('beforeNoteContextRemove', { ntxIds: ntxIdsToRemove }); if (!noteContextToRemove.isMainContext()) { await this.activateNoteContext(noteContextToRemove.getMainContext().ntxId); @@ -336,16 +337,39 @@ export default class TabManager extends Component { } } - this.children = this.children.filter(nc => !ntxIdsToRemove.includes(nc.ntxId)); - - this.recentlyClosedTabs.push(noteContextsToRemove); - - this.triggerEvent('noteContextRemoved', {ntxIds: ntxIdsToRemove}); - - this.tabsUpdate.scheduleUpdate(); + this.removeNoteContexts(noteContextsToRemove); }); } + 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) { + const ntxIdsToRemove = noteContextsToRemove.map(nc => nc.ntxId); + + this.children = this.children.filter(nc => !ntxIdsToRemove.includes(nc.ntxId)); + + this.recentlyClosedTabs.push(noteContextsToRemove); + + this.triggerEvent('noteContextRemoved', {ntxIds: ntxIdsToRemove}); + + this.tabsUpdate.scheduleUpdate(); + } + tabReorderEvent({ntxIdsInOrder}) { const order = {}; diff --git a/src/public/app/widgets/note_detail.js b/src/public/app/widgets/note_detail.js index 0a0790fa8..9027852c1 100644 --- a/src/public/app/widgets/note_detail.js +++ b/src/public/app/widgets/note_detail.js @@ -216,7 +216,7 @@ export default class NoteDetailWidget extends NoteContextAwareWidget { } } - async beforeTabRemoveEvent({ntxIds}) { + async beforeNoteContextRemoveEvent({ntxIds}) { if (this.isNoteContext(ntxIds)) { await this.spacedUpdate.updateNowIfNecessary(); } diff --git a/src/public/app/widgets/note_title.js b/src/public/app/widgets/note_title.js index 59007faa6..2cbd9b5a1 100644 --- a/src/public/app/widgets/note_title.js +++ b/src/public/app/widgets/note_title.js @@ -87,7 +87,7 @@ export default class NoteTitleWidget extends NoteContextAwareWidget { } } - async beforeTabRemoveEvent({ntxIds}) { + async beforeNoteContextRemoveEvent({ntxIds}) { if (this.isNoteContext(ntxIds)) { await this.spacedUpdate.updateNowIfNecessary(); }