From 3004b9e80e4bd5ba9fcabea53e627e3144e26dda Mon Sep 17 00:00:00 2001 From: "Brian R. Bondy" Date: Thu, 22 Dec 2016 21:43:41 -0500 Subject: [PATCH] Set index explicitly on clone Auditors: @bridiver This fixes automated test: inserts after the tab to clone (107ms) Fix #6390 --- app/browser/tabs.js | 33 +++++++++++++++++++++++++++------ js/components/frame.js | 4 ++++ js/components/main.js | 1 + js/stores/windowStore.js | 4 +++- 4 files changed, 35 insertions(+), 7 deletions(-) diff --git a/app/browser/tabs.js b/app/browser/tabs.js index 096ea202310..5c6a56ad9fc 100644 --- a/app/browser/tabs.js +++ b/app/browser/tabs.js @@ -1,5 +1,6 @@ const appActions = require('../../js/actions/appActions') const messages = require('../..//js/constants/messages') +const Immutable = require('immutable') const tabState = require('../common/state/tabState') const {app, extensions} = require('electron') const { makeImmutable } = require('../common/state/immutableUtil') @@ -52,6 +53,11 @@ const api = { } const openerTabId = !source.isDestroyed() ? source.getId() : -1 + let newTabValue = getTabValue(newTab.getId()) + let index + if (newTabValue && newTabValue.get('index') !== -1) { + index = newTabValue.get('index') + } // TODO(bridiver) - handle pinned property?? - probably through tabValue const frameOpts = { @@ -59,7 +65,8 @@ const api = { partition: newTab.session.partition, guestInstanceId: newTab.guestInstanceId, openerTabId, - disposition + disposition, + index } if (disposition === 'new-window' || disposition === 'new-popup') { @@ -81,6 +88,9 @@ const api = { tab.on('set-active', function (evt, active) { updateTab(tabId) }) + tab.on('set-tab-index', function (evt, index) { + updateTab(tabId) + }) tab.on('page-favicon-updated', function (e, favicons) { if (favicons && favicons.length > 0) { // tab.setTabValues({ @@ -138,10 +148,17 @@ const api = { }) process.on('on-tab-created', (tab, options) => { + if (tab.isDestroyed()) { + return + } + + if (options.index !== undefined) { + tab.setTabValues({ + index: options.index + }) + } + tab.once('did-attach', () => { - if (tab.isDestroyed()) { - return - } if (options.back) { tab.goBack() } else if (options.forward) { @@ -173,10 +190,14 @@ const api = { clone: (state, action) => { action = makeImmutable(action) const tabId = action.get('tabId') - const options = action.get('options') + let options = action.get('options') || Immutable.Map() + let tabValue = getTabValue(tabId) + if (tabValue && tabValue.get('index') !== undefined) { + options = options.set('index', tabValue.get('index') + 1) + } const tab = api.getWebContents(tabId) if (tab && !tab.isDestroyed()) { - tab.clone(options && options.toJS() || {}, (newTab) => { + tab.clone(options.toJS(), (newTab) => { }) } return state diff --git a/js/components/frame.js b/js/components/frame.js index 5cfed791a0d..eb16d92b465 100644 --- a/js/components/frame.js +++ b/js/components/frame.js @@ -313,6 +313,7 @@ class Frame extends ImmutableComponent { componentDidMount () { const cb = () => { this.webview.setActive(this.props.isActive) + this.webview.setTabIndex(this.props.tabIndex) this.updateAboutDetails() } this.updateWebview(cb) @@ -364,6 +365,9 @@ class Frame extends ImmutableComponent { this.webview.setWebRTCIPHandlingPolicy(this.getWebRTCPolicy()) } this.webview.setActive(this.props.isActive) + if (prevProps.tabIndex !== this.props.tabIndex) { + this.webview.setTabIndex(this.props.tabIndex) + } this.handleShortcut() // give focus when switching tabs diff --git a/js/components/main.js b/js/components/main.js index 98d5aeeadad..1cbd62f1634 100644 --- a/js/components/main.js +++ b/js/components/main.js @@ -1202,6 +1202,7 @@ class Main extends ImmutableComponent { sortedFrames.map((frame) => { this.frames[frame.get('key')] = node }} + tabIndex={FrameStateUtil.getFrameIndex(this.props.windowState, frame.get('key'))} prefOpenInForeground={getSetting(settings.SWITCH_TO_NEW_TABS)} onCloseFrame={this.onCloseFrame} frameKey={frame.get('key')} diff --git a/js/stores/windowStore.js b/js/stores/windowStore.js index 16bad98f27b..cf964c08f68 100644 --- a/js/stores/windowStore.js +++ b/js/stores/windowStore.js @@ -170,7 +170,9 @@ const newFrame = (frameOpts, openInForeground, insertionIndex, nextKey) => { frameOpts = frameOpts.toJS ? frameOpts.toJS() : frameOpts // handle tabs.create properties - insertionIndex = frameOpts.index || insertionIndex + insertionIndex = frameOpts.index !== undefined + ? frameOpts.index + : insertionIndex if (frameOpts.partition) { frameOpts.isPrivate = frameStateUtil.isPrivatePartition(frameOpts.partition)