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

Commit

Permalink
Added last active tab close option
Browse files Browse the repository at this point in the history
  • Loading branch information
NejcZdovc committed Feb 27, 2017
1 parent e82c151 commit 4be5b03
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 11 deletions.
19 changes: 17 additions & 2 deletions js/state/frameStateUtil.js
Original file line number Diff line number Diff line change
Expand Up @@ -502,7 +502,7 @@ function removeFrame (frames, tabs, closedFrames, frameProps, activeFrameKey, fr
* Removes a frames specified by framePropsList
* @return Immutable top level application state ready to merge back in
*/
function removeFrames (frames, tabs, closedFrames, framePropsList, activeFrameRemoved, activeFrameKey) {
function removeFrames (frames, tabs, closedFrames, framePropsList, activeFrameRemoved, activeFrameKey, closeAction) {
function getLastTab (newFrames) {
const sorted = newFrames
.filter((frame) => !frame.get('pinnedLocation'))
Expand All @@ -511,6 +511,14 @@ function removeFrames (frames, tabs, closedFrames, framePropsList, activeFrameRe
return (sorted.size === 0) ? 0 : sorted.last().get('key')
}

function getLastActiveTab (newFrames) {
const sorted = newFrames
.filter((frame) => !frame.get('pinnedLocation'))
.sortBy((item) => item.get('lastAccessedTime') || 0)

return (sorted.size === 0) ? 0 : sorted.last().get('key')
}

let newFrames = makeImmutable(frames)
let newTabs = makeImmutable(tabs)

Expand All @@ -533,7 +541,14 @@ function removeFrames (frames, tabs, closedFrames, framePropsList, activeFrameRe

// return last non pinned frame index if active frame was removed
if (activeFrameRemoved) {
activeFrameKey = getLastTab(newFrames)
switch (closeAction) {
case tabCloseAction.LAST_ACTIVE:
activeFrameKey = getLastActiveTab(newFrames)
break
default:
activeFrameKey = getLastTab(newFrames)
break
}
}

return {
Expand Down
3 changes: 2 additions & 1 deletion js/stores/windowStore.js
Original file line number Diff line number Diff line change
Expand Up @@ -375,7 +375,8 @@ const doAction = (action) => {
windowState.get('closedFrames'),
action.framePropsList,
action.activeFrameRemoved,
windowState.get('activeFrameKey')
windowState.get('activeFrameKey'),
getSetting(settings.TAB_CLOSE_ACTION)
))

updateTabPageIndex(frameStateUtil.getActiveFrame(windowState))
Expand Down
23 changes: 15 additions & 8 deletions test/unit/state/frameStateUtilTest.js
Original file line number Diff line number Diff line change
Expand Up @@ -292,10 +292,11 @@ describe('frameStateUtil', function () {
{ key: 2 },
{ key: 3, parentFrameKey: 2 },
{ key: 4 },
{ key: 5, pinnedLocation: 'https://twitter.com/' },
{ key: 6 },
{ key: 7 },
{ key: 8, pinnedLocation: 'https://brave.com/' }
{ key: 5, pinnedLocation: 'https://twitter.com/', lastAccessedTime: 1488184050731 },
{ key: 6, lastAccessedTime: 1488184050721 },
{ key: 7, lastAccessedTime: undefined },
{ key: 8, lastAccessedTime: 1488184050711 },
{ key: 9, pinnedLocation: 'https://brave.com/' }
])
tabs = Immutable.fromJS([
{ key: 2 },
Expand All @@ -304,7 +305,8 @@ describe('frameStateUtil', function () {
{ key: 5, pinnedLocation: 'https://twitter.com/' },
{ key: 6 },
{ key: 7 },
{ key: 8, pinnedLocation: 'https://brave.com/' }
{ key: 8 },
{ key: 9, pinnedLocation: 'https://brave.com/' }
])
closedFrames = Immutable.fromJS([
{ key: 1 }
Expand All @@ -321,7 +323,7 @@ describe('frameStateUtil', function () {

it('removes frames from `frames`', function () {
const result = frameStateUtil.removeFrames(frames, tabs, closedFrames, framePropsList, undefined, activeFrameKeyKeep)
assert.equal(4, result.frames.size)
assert.equal(5, result.frames.size)
})

it('removed frames are in `closedFrame`', function () {
Expand All @@ -341,9 +343,14 @@ describe('frameStateUtil', function () {
assert.equal(true, inFrames === undefined)
})

it('new active frame', function () {
it('new active frame (last tab)', function () {
const result = frameStateUtil.removeFrames(frames, tabs, closedFrames, framePropsList, activeFrameRemoved, activeFrameKey)
assert.equal(7, result.activeFrameKey)
assert.equal(8, result.activeFrameKey)
})

it('new active frame (last active tab)', function () {
const result = frameStateUtil.removeFrames(frames, tabs, closedFrames, framePropsList, activeFrameRemoved, activeFrameKey, tabCloseAction.LAST_ACTIVE)
assert.equal(6, result.activeFrameKey)
})
})
})
Expand Down

0 comments on commit 4be5b03

Please sign in to comment.