Skip to content

Commit

Permalink
Fixes close tabs to the left/right
Browse files Browse the repository at this point in the history
when you have multiple tab pages

Resolves brave#9789

Auditors: @bsclifton

Test Plan:
  • Loading branch information
NejcZdovc committed Jul 12, 2017
1 parent c8e92a1 commit 84aee6e
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 11 deletions.
34 changes: 23 additions & 11 deletions app/renderer/reducers/frameReducer.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
10 changes: 10 additions & 0 deletions test/tab-components/tabPagesTest.js
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 84aee6e

Please sign in to comment.