From 84aee6e5c02c118d6b825d5169cf2f3513ffdc05 Mon Sep 17 00:00:00 2001 From: NejcZdovc Date: Fri, 30 Jun 2017 10:28:33 +0200 Subject: [PATCH] Fixes close tabs to the left/right when you have multiple tab pages Resolves #9789 Auditors: @bsclifton Test Plan: --- app/renderer/reducers/frameReducer.js | 34 ++++++++++++++++++--------- test/tab-components/tabPagesTest.js | 10 ++++++++ 2 files changed, 33 insertions(+), 11 deletions(-) diff --git a/app/renderer/reducers/frameReducer.js b/app/renderer/reducers/frameReducer.js index 44d9e12f443..8640edb0ce6 100644 --- a/app/renderer/reducers/frameReducer.js +++ b/app/renderer/reducers/frameReducer.js @@ -186,21 +186,33 @@ const frameReducer = (state, action, immutableAction) => { }) break case windowConstants.WINDOW_CLOSE_OTHER_FRAMES: - const currentIndex = frameStateUtil.getIndexByTabId(state, action.tabId) - if (currentIndex === -1) { - return - } + { + const currentIndex = frameStateUtil.getIndexByTabId(state, action.tabId) + if (currentIndex === -1) { + return + } - state.get('frames').forEach((frame, i) => { - if (!frame.get('pinnedLocation') && - ((i < currentIndex && action.isCloseLeft) || (i > currentIndex && action.isCloseRight))) { - if (frame) { - appActions.tabCloseRequested(frame.get('tabId')) + let tabs = [] + + state.get('frames').forEach((frame, i) => { + if (!frame.get('pinnedLocation') && + ((i < currentIndex && action.isCloseLeft) || (i > currentIndex && action.isCloseRight))) { + if (frame) { + tabs.push(frame.get('tabId')) + appActions.tabCloseRequested(frame.get('tabId')) + } } - } - }) + }) + // TODO(nejc) this can be simplified when states are merged + const newFrames = state.get('frames').filter(frame => !tabs.includes(frame.get('tabId'))) + let newState = state.set('frames', newFrames) + newState = frameStateUtil.updateTabPageIndex(newState, action.tabId) + const index = newState.getIn(['ui', 'tabs', 'tabPageIndex'], 0) + state = state.setIn(['ui', 'tabs', 'tabPageIndex'], index) + } break + case windowConstants.WINDOW_CLOSE_FRAME: state = closeFrame(state, action) break diff --git a/test/tab-components/tabPagesTest.js b/test/tab-components/tabPagesTest.js index b419b19c9dd..ee53a7cb66d 100644 --- a/test/tab-components/tabPagesTest.js +++ b/test/tab-components/tabPagesTest.js @@ -3,6 +3,7 @@ const Brave = require('../lib/brave') const appConfig = require('../../js/constants/appConfig') const settings = require('../../js/constants/settings') +const messages = require('../../js/constants/messages') const { urlInput, newFrameButton, @@ -68,6 +69,15 @@ describe('tab pages', function () { .waitForElementCount(tabsTabs, numTabsPerPage) }) + it('closing tabs with close-to-left option', function * () { + yield this.app.client + .click(newFrameButton) + .waitForElementCount(tabPage, 2) + .ipcSend(messages.SHORTCUT_CLOSE_OTHER_FRAMES, 21, false, true) + .waitForElementCount(tabPage, 0) + .waitForElementCount(tabsTabs, 1) + }) + describe('allows changing to tab pages', function () { beforeEach(function * () { // Make sure there are 2 tab pages