From 6982204e68dd919dc123243eda0696a1d4a55eec Mon Sep 17 00:00:00 2001 From: lana-k Date: Mon, 3 Jul 2023 23:13:09 +0200 Subject: [PATCH] Update currentTab when close tabs #112 --- src/store/mutations.js | 4 +++- tests/store/mutations.spec.js | 16 ++++++++++++---- 2 files changed, 15 insertions(+), 5 deletions(-) diff --git a/src/store/mutations.js b/src/store/mutations.js index b31f07c..8eb1954 100644 --- a/src/store/mutations.js +++ b/src/store/mutations.js @@ -36,9 +36,11 @@ export default { state.currentTabId = state.tabs[index - 1].id } else { state.currentTabId = null - state.currentTab = null state.untitledLastIndex = 0 } + state.currentTab = state.currentTabId + ? state.tabs.find(tab => tab.id === state.currentTabId) + : null } state.tabs.splice(index, 1) }, diff --git a/tests/store/mutations.spec.js b/tests/store/mutations.spec.js index cf05502..9c61234 100644 --- a/tests/store/mutations.spec.js +++ b/tests/store/mutations.spec.js @@ -176,13 +176,15 @@ describe('mutations', () => { const state = { tabs: [tab1, tab2], - currentTabId: 1 + currentTabId: 1, + currentTab: tab1 } deleteTab(state, tab1) expect(state.tabs).to.have.lengthOf(1) expect(state.tabs[0].id).to.equal(2) expect(state.currentTabId).to.equal(2) + expect(state.currentTab).to.eql(tab2) }) it('deleteTab - opened, last', () => { @@ -208,13 +210,15 @@ describe('mutations', () => { const state = { tabs: [tab1, tab2], - currentTabId: 2 + currentTabId: 2, + currentTab: tab2 } deleteTab(state, tab2) expect(state.tabs).to.have.lengthOf(1) expect(state.tabs[0].id).to.equal(1) expect(state.currentTabId).to.equal(1) + expect(state.currentTab).to.eql(tab1) }) it('deleteTab - opened, in the middle', () => { @@ -250,7 +254,8 @@ describe('mutations', () => { const state = { tabs: [tab1, tab2, tab3], - currentTabId: 2 + currentTabId: 2, + currentTab: tab2 } deleteTab(state, tab2) @@ -258,6 +263,7 @@ describe('mutations', () => { expect(state.tabs[0].id).to.equal(1) expect(state.tabs[1].id).to.equal(3) expect(state.currentTabId).to.equal(3) + expect(state.currentTab).to.eql(tab3) }) it('deleteTab - opened, single', () => { @@ -273,12 +279,14 @@ describe('mutations', () => { const state = { tabs: [tab1], - currentTabId: 1 + currentTabId: 1, + currentTab: tab1 } deleteTab(state, tab1) expect(state.tabs).to.have.lengthOf(0) expect(state.currentTabId).to.equal(null) + expect(state.currentTab).to.equal(null) }) it('setCurrentTabId', () => {