diff --git a/js/state/frameStateUtil.js b/js/state/frameStateUtil.js index f27316d924d..00161dbdb4a 100644 --- a/js/state/frameStateUtil.js +++ b/js/state/frameStateUtil.js @@ -284,7 +284,7 @@ const tabFromFrame = (frame) => { * 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 (frames, tabs, frameOpts, newKey, partitionNumber, activeFrameKey) { +function addFrame (frames, tabs, frameOpts, newKey, partitionNumber, activeFrameKey, insertionIndex) { const url = frameOpts.location || config.defaultUrl // delayedLoadUrl is used as a placeholder when the new frame is created @@ -352,22 +352,6 @@ function addFrame (frames, tabs, frameOpts, newKey, partitionNumber, activeFrame history: [] }, frameOpts)) - // Find the closest index to the current frame's index which has - // a different ancestor frame key. - let insertionIndex = findIndexForFrameKey(frames, frameOpts.parentFrameKey) - if (insertionIndex === -1) { - insertionIndex = frames.size - } - while (insertionIndex < frames.size) { - ++insertionIndex - if (!isAncestorFrameKey(frames, frames.get(insertionIndex), frameOpts.parentFrameKey)) { - break - } - } - if (isFrameKeyPinned(frames, frameOpts.parentFrameKey)) { - insertionIndex = 0 - } - return { tabs: tabs.splice(insertionIndex, 0, tabFromFrame(frame)), frames: frames.splice(insertionIndex, 0, frame), @@ -505,7 +489,9 @@ function getFrameTabPageIndex (frames, frameProps, tabsPerTabPage) { module.exports = { query, find, + isAncestorFrameKey, isFrameKeyActive, + isFrameKeyPinned, getFrameIndex, getFrameDisplayIndex, getActiveFrameIndex, diff --git a/js/stores/windowStore.js b/js/stores/windowStore.js index 07605995dec..d7df0c08988 100644 --- a/js/stores/windowStore.js +++ b/js/stores/windowStore.js @@ -154,7 +154,9 @@ const addToHistory = (frameProps) => { return history.slice(-10) } -const newFrame = (frameOpts, openInForeground) => { +const newFrame = (frameOpts, openInForeground, insertionIndex) => { + const frames = windowState.get('frames') + if (frameOpts === undefined) { frameOpts = {} } @@ -185,8 +187,31 @@ const newFrame = (frameOpts, openInForeground) => { } else if (frameOpts.isPartitioned) { nextPartitionNumber = incrementPartitionNumber() } - windowState = windowState.merge(FrameStateUtil.addFrame(windowState.get('frames'), windowState.get('tabs'), frameOpts, - nextKey, nextPartitionNumber, openInForeground ? nextKey : windowState.get('activeFrameKey'))) + + // Find the closest index to the current frame's index which has + // a different ancestor frame key. + if (!insertionIndex) { + insertionIndex = FrameStateUtil.findIndexForFrameKey(frames, frameOpts.parentFrameKey) + } + if (insertionIndex === -1) { + insertionIndex = frames.size + } + while (insertionIndex < frames.size) { + ++insertionIndex + if (!FrameStateUtil.isAncestorFrameKey(frames, frames.get(insertionIndex), frameOpts.parentFrameKey)) { + break + } + } + if (FrameStateUtil.isFrameKeyPinned(frames, frameOpts.parentFrameKey)) { + insertionIndex = 0 + } + + windowState = windowState.merge( + FrameStateUtil.addFrame( + frames, windowState.get('tabs'), frameOpts, + nextKey, nextPartitionNumber, openInForeground ? nextKey : windowState.get('activeFrameKey'), insertionIndex) + ) + if (openInForeground) { const activeFrame = FrameStateUtil.getActiveFrame(windowState) updateTabPageIndex(activeFrame)