Skip to content
This repository has been archived by the owner on Dec 11, 2019. It is now read-only.

Fixes close tabs to the left/right #9790

Merged
merged 1 commit into from
Jul 14, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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) {
break
}

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
2 changes: 1 addition & 1 deletion test/lib/brave.js
Original file line number Diff line number Diff line change
Expand Up @@ -202,7 +202,7 @@ var exports = {
const initialized = []

this.app.client.addCommand('ipcSend', function (message, ...param) {
logVerbose('ipcSend(' + message + ')')
logVerbose('ipcSend(' + message + ', "' + param + '")')
return this.execute(function (message, ...param) {
return devTools('electron').remote.getCurrentWindow().webContents.send(message, ...param)
}, message, ...param).then((response) => response.value)
Expand Down
20 changes: 20 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,25 @@ describe('tab pages', function () {
.waitForElementCount(tabsTabs, numTabsPerPage)
})

it('closing tabs with close-to-left option', function * () {
let tabId = 0
yield this.app.client
.click(newFrameButton)
.waitForElementCount(tabPage, 2)
.waitUntil(function () {
return this.getAppState().then((state) => {
const length = state.value.tabs.length
tabId = state.value.tabs[length - 1].id
return true
})
})
.waitUntil(function () {
return this.ipcSend(messages.SHORTCUT_CLOSE_OTHER_FRAMES, tabId, 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