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

Commit

Permalink
single-webview next active tab fix
Browse files Browse the repository at this point in the history
Fix #13733
  • Loading branch information
petemill committed Apr 30, 2018
1 parent e3868cb commit fd09831
Showing 1 changed file with 30 additions and 23 deletions.
53 changes: 30 additions & 23 deletions app/browser/tabs.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) => {
updateTab(tab.getId(), { active: isActive })
if (isActive) {
Expand Down Expand Up @@ -740,6 +717,7 @@ const api = {
})

tab.once('will-destroy', (e) => {
api.willBeRemovedFromWindow(tabId)
const tabValue = getTabValue(tabId)
if (tabValue) {
const windowId = tabValue.get('windowId')
Expand Down Expand Up @@ -853,6 +831,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')
Expand Down Expand Up @@ -1099,6 +1104,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
}
Expand All @@ -1113,6 +1119,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)
},
Expand Down

0 comments on commit fd09831

Please sign in to comment.