From e712990c03c76f255c4538a4cab5d7d0b18832de Mon Sep 17 00:00:00 2001 From: zadam Date: Tue, 26 Nov 2019 20:42:34 +0100 Subject: [PATCH] don't remove active tab after deleting note to preserve tab state, fixes #727 --- src/public/javascripts/services/note_detail.js | 4 +++- src/public/javascripts/services/tab_context.js | 6 +++++- 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/src/public/javascripts/services/note_detail.js b/src/public/javascripts/services/note_detail.js index 5c41515da..dd3445302 100644 --- a/src/public/javascripts/services/note_detail.js +++ b/src/public/javascripts/services/note_detail.js @@ -273,7 +273,9 @@ async function filterTabs(noteId) { async function noteDeleted(noteId) { for (const tc of tabContexts) { - if (tc.notePath && tc.notePath.split("/").includes(noteId)) { + // not removing active even if it contains deleted note since that one will move to another note (handled by deletion logic) + // and we would lose tab context state (e.g. sidebar visibility) + if (!tc.isActive() && tc.notePath && tc.notePath.split("/").includes(noteId)) { await tabRow.removeTab(tc.$tab[0]); } } diff --git a/src/public/javascripts/services/tab_context.js b/src/public/javascripts/services/tab_context.js index f276832d5..5b2fd2eb8 100644 --- a/src/public/javascripts/services/tab_context.js +++ b/src/public/javascripts/services/tab_context.js @@ -246,11 +246,15 @@ class TabContext { } setCurrentNotePathToHash() { - if (this.$tab[0] === this.tabRow.activeTabEl) { + if (this.isActive()) { document.location.hash = (this.notePath || "") + "-" + this.tabId; } } + isActive() { + return this.$tab[0] === this.tabRow.activeTabEl; + } + setupClasses() { for (const clazz of Array.from(this.$tab[0].classList)) { // create copy to safely iterate over while removing classes if (clazz !== 'note-tab') {