From ed5ededcbe45776e0a763cdb46aba75c10371dca Mon Sep 17 00:00:00 2001 From: dragonwocky Date: Thu, 15 Oct 2020 23:59:18 +1100 Subject: [PATCH] better tab picking on close: find closest/next instead of jumping to first --- mods/core/render.js | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/mods/core/render.js b/mods/core/render.js index f5765fe..7f15aff 100644 --- a/mods/core/render.js +++ b/mods/core/render.js @@ -225,7 +225,12 @@ module.exports = (store, __exports) => { openTab(id, state = new Map(this.state.tabs), load) { if (!id && id !== 0) { if (state.get(this.views.current.id)[1]) return; - id = [...state].find(([id, [title, open]]) => open)[0]; + const currentIndex = [...state].findIndex( + ([id, [title, open]]) => id === this.views.current.id + ); + id = ([...state].find( + ([id, [title, open]], tabIndex) => open && tabIndex > currentIndex + ) || [...state].find(([id, [title, open]]) => open))[0]; } const current_src = this.views.current.$el().src; this.views.current.id = id; @@ -280,9 +285,7 @@ module.exports = (store, __exports) => { if (![...list].filter(([id, [title, open]]) => open).length) return electron.remote.getCurrentWindow().close(); this.openTab( - this.views.current.id === id - ? null - : [...list].find(([id, [title, open]]) => open)[0], + this.views.current.id === id ? null : this.views.current.id, list ); }