From c2f6c7349f7cae96cf8b7436c767483d704a1e63 Mon Sep 17 00:00:00 2001 From: petemill Date: Wed, 4 Apr 2018 15:41:49 -0700 Subject: [PATCH] single-webview next active tab fix Fix #13733 --- app/browser/tabs.js | 53 +++++++++++++++++++++++++-------------------- 1 file changed, 30 insertions(+), 23 deletions(-) diff --git a/app/browser/tabs.js b/app/browser/tabs.js index 4e0d95b415d..995ee8883c3 100644 --- a/app/browser/tabs.js +++ b/app/browser/tabs.js @@ -627,29 +627,6 @@ const api = { appActions.tabWillAttach(tab.getId()) }) - tab.on('tab-detached-at', () => { - const tabValue = getTabValue(tabId) - if (tabValue) { - const windowId = tabValue.get('windowId') - if (shouldDebugTabEvents) { - console.log(`tab ${tabId} detached from window ${windowId}`) - } - // forget about this tab in the history of active tabs - activeTabHistory.clearTabFromWindow(windowId, tabId) - // handle closed tab being the current active tab for window - if (tabValue.get('active')) { - // set the next active tab, if different from what muon will have set to - // Muon sets it to the next index (immediately above or below) - // But this app can be configured to select the parent tab, - // or the last active tab - let nextTabId = api.getNextActiveTabId(windowId, tabId) - if (nextTabId != null) { - api.setActive(nextTabId) - } - } - } - }) - tab.on('set-active', (sender, isActive) => { if (isActive) { const tabValue = getTabValue(tabId) @@ -739,6 +716,7 @@ const api = { }) tab.once('will-destroy', (e) => { + api.willBeRemovedFromWindow(tabId) const tabValue = getTabValue(tabId) if (tabValue) { const windowId = tabValue.get('windowId') @@ -852,6 +830,33 @@ const api = { } }, + willBeRemovedFromWindow (tabId) { + const tabValue = getTabValue(tabId) + if (tabValue) { + const windowId = tabValue.get('windowId') + const wasActive = tabValue.get('active') + if (shouldDebugTabEvents) { + console.log(`tab ${tabId} will be removed from window ${windowId}, wasActive: ${wasActive}`) + } + // forget about this tab in the history of active tabs + activeTabHistory.clearTabFromWindow(windowId, tabId) + // handle closed tab being the current active tab for window + if (wasActive) { + // set the next active tab, if different from what muon will have set to + // Muon sets it to the next index (immediately above or below) + // But this app can be configured to select the parent tab, + // or the last active tab + let nextTabId = api.getNextActiveTabId(windowId, tabId) + if (nextTabId != null) { + if (shouldDebugTabEvents) { + console.log(`Got next active tab Id of ${nextTabId}`) + } + api.setActive(nextTabId) + } + } + } + }, + loadURL: (action) => { action = makeImmutable(action) const tabId = action.get('tabId') @@ -1098,6 +1103,7 @@ const api = { // create a new window if required if (toWindowId == null || toWindowId === -1) { // this will eventually call tab.moveTo when the window is known + api.willBeRemovedFromWindow(tabId, currentWindowId) appActions.newWindow(frameOpts, browserOpts) return } @@ -1112,6 +1118,7 @@ const api = { console.error('Error: invalid window to move tab to') return } + api.willBeRemovedFromWindow(tabId, currentWindowId) notifyWindowWebContentsAdded(toWindowId, frameOpts.toJS(), tabValue.toJS()) tab.moveTo(toIndex, toWindowId) },