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

Commit

Permalink
Merge pull request #9182 from brave/9165
Browse files Browse the repository at this point in the history
Fix active frame issue when tearing off inactive tab from window
  • Loading branch information
bsclifton authored and bbondy committed May 31, 2017
1 parent 4ce9744 commit b097dcb
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 8 deletions.
13 changes: 10 additions & 3 deletions js/state/frameStateUtil.js
Original file line number Diff line number Diff line change
Expand Up @@ -284,14 +284,15 @@ const frameOptsFromFrame = (frame) => {
.delete('parentFrameKey')
.delete('activeShortcut')
.delete('activeShortcutDetails')
.delete('index')
.deleteIn(['navbar', 'urlbar', 'suggestions'])
}

/**
* Adds a frame specified by frameOpts and newKey and sets the activeFrameKey
* @return Immutable top level application state ready to merge back in
*/
function addFrame (state, frameOpts, newKey, partitionNumber, activeFrameKey, insertionIndex) {
function addFrame (state, frameOpts, newKey, partitionNumber, openInForeground, insertionIndex) {
const frames = state.get('frames')
const url = frameOpts.location || config.defaultUrl

Expand Down Expand Up @@ -324,7 +325,7 @@ function addFrame (state, frameOpts, newKey, partitionNumber, activeFrameKey, in
loading: !!delayedLoadUrl,
startLoadTime: delayedLoadUrl ? new Date().getTime() : null,
endLoadTime: null,
lastAccessedTime: (activeFrameKey === newKey) ? new Date().getTime() : null,
lastAccessedTime: openInForeground ? new Date().getTime() : null,
isPrivate: false,
partitionNumber,
pinnedLocation: isPinned ? url : undefined,
Expand Down Expand Up @@ -356,9 +357,15 @@ function addFrame (state, frameOpts, newKey, partitionNumber, activeFrameKey, in
history: []
}, frameOpts))

return {
const result = {
frames: frames.splice(insertionIndex, 0, frame)
}

if (openInForeground) {
result.activeFrameKey = newKey
}

return result
}

/**
Expand Down
14 changes: 9 additions & 5 deletions js/stores/windowStore.js
Original file line number Diff line number Diff line change
Expand Up @@ -174,20 +174,22 @@ const newFrame = (state, frameOpts, openInForeground, insertionIndex, nextKey) =

if (nextKey === undefined) {
nextKey = incrementNextKey()
openInForeground = true
}

state = state.merge(
frameStateUtil.addFrame(
state, frameOpts,
nextKey, frameOpts.partitionNumber, openInForeground || typeof state.get('activeFrameKey') !== 'number' ? nextKey : state.get('activeFrameKey'), insertionIndex))
nextKey, frameOpts.partitionNumber, openInForeground, insertionIndex))

state = frameStateUtil.updateFramesInternalIndex(state, insertionIndex)

if (openInForeground) {
const activeFrame = frameStateUtil.getActiveFrame(state)
const tabId = activeFrame.get('tabId')
state = updateTabPageIndex(state, activeFrame)
if (activeFrame.get('tabId')) {
appActions.tabActivateRequested(activeFrame.get('tabId'))
if (tabId) {
appActions.tabActivateRequested(tabId)
}
}

Expand Down Expand Up @@ -351,8 +353,10 @@ const doAction = (action) => {
break
case windowConstants.WINDOW_SET_PREVIEW_FRAME:
windowState = windowState.merge({
previewFrameKey: action.frameKey != null && action.frameKey !== windowState.get('activeFrameKey')
? action.frameKey : null
previewFrameKey:
action.frameKey != null && !frameStateUtil.isFrameKeyActive(windowState, action.frameKey)
? action.frameKey
: null
})
break
case windowConstants.WINDOW_SET_PREVIEW_TAB_PAGE_INDEX:
Expand Down
1 change: 1 addition & 0 deletions test/tab-components/tabTest.js
Original file line number Diff line number Diff line change
Expand Up @@ -510,6 +510,7 @@ describe('tab tests', function () {
.detachTabByIndex(1)
.waitForWindowCount(2)
.waitForTab({index: 0, url: this.page1, windowId: 2})
.waitForElementCount('.frameWrapper.isActive', 1)
})

it('can move into an existing window', function * () {
Expand Down

0 comments on commit b097dcb

Please sign in to comment.