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

Cloned tabs appear next to the original one #3134

Merged
merged 2 commits into from
Aug 12, 2016
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
20 changes: 3 additions & 17 deletions js/state/frameStateUtil.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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),
Expand Down Expand Up @@ -505,7 +489,9 @@ function getFrameTabPageIndex (frames, frameProps, tabsPerTabPage) {
module.exports = {
query,
find,
isAncestorFrameKey,
isFrameKeyActive,
isFrameKeyPinned,
getFrameIndex,
getFrameDisplayIndex,
getActiveFrameIndex,
Expand Down
35 changes: 31 additions & 4 deletions js/stores/windowStore.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 = {}
}
Expand Down Expand Up @@ -185,8 +187,32 @@ 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 === undefined) {
insertionIndex = FrameStateUtil.findIndexForFrameKey(frames, frameOpts.parentFrameKey)
if (insertionIndex === -1) {
insertionIndex = frames.size
} else {
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)
Expand Down Expand Up @@ -390,7 +416,8 @@ const doAction = (action) => {
newFrame(action.frameOpts, action.openInForeground)
break
case WindowConstants.WINDOW_CLONE_FRAME:
newFrame(FrameStateUtil.cloneFrame(action.frameOpts, action.guestInstanceId), action.openInForeground)
let insertionIndex = FrameStateUtil.findIndexForFrameKey(windowState.get('frames'), action.frameOpts.key) + 1
newFrame(FrameStateUtil.cloneFrame(action.frameOpts, action.guestInstanceId), action.openInForeground, insertionIndex)
break
case WindowConstants.WINDOW_CLOSE_FRAME:
// Use the frameProps we passed in, or default to the active frame
Expand Down
42 changes: 41 additions & 1 deletion test/components/frameTest.js
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,47 @@ describe('clone tab', function () {
})
})

describe('index', function () {
Brave.beforeAll(this)

before(function * () {
this.clickWithTargetPage = Brave.server.url('click_with_target.html')
this.page1 = Brave.server.url('page1.html')

yield setup(this.app.client)
yield this.app.client
.waitUntilWindowLoaded()
.windowByUrl(Brave.browserWindowUrl)
.waitForUrl(Brave.newTabUrl)
.url(this.clickWithTargetPage)
.waitForVisible('#name')
.click('#name')
yield this.app.client
.windowByUrl(Brave.browserWindowUrl)
.waitForExist('.tab[data-frame-key="2"]')
yield this.app.client
.ipcSend('shortcut-set-active-frame-by-index', 0)
.windowByUrl(Brave.browserWindowUrl)
.ipcSend(messages.SHORTCUT_ACTIVE_FRAME_CLONE)
.waitUntil(function () {
return this.getTabCount().then((count) => {
return count === 3
})
})
})

it('inserts after the tab to clone', function * () {
this.tab1 = '.tabArea:nth-child(1) .tab[data-frame-key="1"]'
this.tab2 = '.tabArea:nth-child(2) .tab[data-frame-key="3"]'
this.tab3 = '.tabArea:nth-child(3) .tab[data-frame-key="2"]'
yield this.app.client
.windowByUrl(Brave.browserWindowUrl)
.waitForExist(this.tab1)
.waitForExist(this.tab2)
.waitForExist(this.tab3)
})
})

describe('history', function () {
Brave.beforeAll(this)

Expand Down Expand Up @@ -283,4 +324,3 @@ function * setup (client) {
.waitForVisible('#window')
.waitForVisible(urlInput)
}