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

Commit

Permalink
Use muon's tab_strip_model for driving index and active
Browse files Browse the repository at this point in the history
Fix #10436
Fix #9385
Fix #9722
Fix #10561
Fix #9083
Fix #9671
Fix #10038
Fix #10384
Fix #10532

and probably several others.
  • Loading branch information
bbondy committed Aug 23, 2017
1 parent 12cd539 commit 5805ca0
Show file tree
Hide file tree
Showing 19 changed files with 361 additions and 226 deletions.
103 changes: 42 additions & 61 deletions app/browser/reducers/tabsReducer.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ const windows = require('../windows')
const {getWebContents} = require('../webContentsCache')
const {BrowserWindow} = require('electron')
const tabState = require('../../common/state/tabState')
const windowState = require('../../common/state/windowState')
const tabActions = require('../../common/actions/tabActions')
const siteSettings = require('../../../js/state/siteSettings')
const siteSettingsState = require('../../common/state/siteSettingsState')
Expand All @@ -22,63 +21,9 @@ const {getFlashResourceId} = require('../../../js/flash')
const {l10nErrorText} = require('../../common/lib/httpUtil')
const Immutable = require('immutable')
const dragTypes = require('../../../js/constants/dragTypes')
const getSetting = require('../../../js/settings').getSetting
const settings = require('../../../js/constants/settings')
const {tabCloseAction} = require('../../common/constants/settingsEnums')
const {frameOptsFromFrame} = require('../../../js/state/frameStateUtil')
const {isSourceAboutUrl, isTargetAboutUrl, isNavigatableAboutPage} = require('../../../js/lib/appUrlUtil')

const updateActiveTab = (state, closeTabId) => {
if (!tabState.getByTabId(state, closeTabId)) {
return
}

const index = tabState.getIndex(state, closeTabId)
if (index === -1) {
return
}

const windowId = tabState.getWindowId(state, closeTabId)
if (windowId === windowState.WINDOW_ID_NONE) {
return
}

const lastActiveTabId = tabState.getTabsByLastActivated(state, windowId).last()
if (lastActiveTabId !== closeTabId && !tabState.isActive(state, closeTabId)) {
return
}

let nextTabId = tabState.TAB_ID_NONE
switch (getSetting(settings.TAB_CLOSE_ACTION)) {
case tabCloseAction.LAST_ACTIVE:
nextTabId = tabState.getLastActiveTabId(state, windowId)
break
case tabCloseAction.PARENT:
{
const openerTabId = tabState.getOpenerTabId(state, closeTabId)
if (openerTabId !== tabState.TAB_ID_NONE) {
nextTabId = openerTabId
}
break
}
}

// DEFAULT: always fall back to NEXT
if (nextTabId === tabState.TAB_ID_NONE) {
nextTabId = tabState.getNextTabIdByIndex(state, windowId, index)
if (nextTabId === tabState.TAB_ID_NONE) {
// no unpinned tabs so find the next pinned tab
nextTabId = tabState.getNextTabIdByIndex(state, windowId, index, true)
}
}

if (nextTabId !== tabState.TAB_ID_NONE) {
setImmediate(() => {
tabs.setActive(nextTabId)
})
}
}

const WEBRTC_DEFAULT = 'default'
const WEBRTC_DISABLE_NON_PROXY = 'disable_non_proxied_udp'

Expand Down Expand Up @@ -126,7 +71,23 @@ const tabsReducer = (state, action, immutableAction) => {
case appConstants.APP_TAB_CREATED:
state = tabState.maybeCreateTab(state, action)
break
case appConstants.APP_TAB_MOVED: {
case appConstants.APP_TAB_ATTACHED:
tabs.updateTabsStateForAttachedTab(state, action.get('tabId'))
break
case appConstants.APP_TAB_WILL_ATTACH: {
const tabId = action.get('tabId')
const tabValue = tabState.getByTabId(state, tabId)
if (!tabValue) {
break
}
const oldWindowId = tabState.getWindowId(state, tabId)
tabs.updateTabsStateForWindow(state, oldWindowId)
break
}
case appConstants.APP_TAB_MOVED:
tabs.updateTabsStateForAttachedTab(state, action.get('tabId'))
break
case appConstants.APP_TAB_DETACH_MENU_ITEM_CLICKED: {
setImmediate(() => {
const tabId = action.get('tabId')
const frameOpts = frameOptsFromFrame(action.get('frameOpts'))
Expand Down Expand Up @@ -158,6 +119,7 @@ const tabsReducer = (state, action, immutableAction) => {
break
case appConstants.APP_TAB_UPDATED:
state = tabState.maybeCreateTab(state, action)
// tabs.debugTabs(state)
break
case appConstants.APP_TAB_CLOSE_REQUESTED:
{
Expand Down Expand Up @@ -194,7 +156,7 @@ const tabsReducer = (state, action, immutableAction) => {
tabs.closeTab(tabId, action.get('forceClosePinned'))
})
} else {
state = windows.closeWindow(state, windowId)
windows.closeWindow(windowId)
}
}
}
Expand All @@ -206,8 +168,21 @@ const tabsReducer = (state, action, immutableAction) => {
if (tabId === tabState.TAB_ID_NONE) {
break
}
updateActiveTab(state, tabId)
const nextActiveTabId = tabs.getNextActiveTab(state, tabId)

// Must be called before tab is removed
// But still check for no tabId because on tab detach there's a dummy tabId
const tabValue = tabState.getByTabId(state, tabId)
if (tabValue) {
const windowIdOfTabBeingRemoved = tabState.getWindowId(state, tabId)
tabs.updateTabsStateForWindow(state, windowIdOfTabBeingRemoved)
}
state = tabState.removeTabByTabId(state, tabId)
setImmediate(() => {
if (nextActiveTabId !== tabState.TAB_ID_NONE) {
tabs.setActive(nextActiveTabId)
}
})
}
break
case appConstants.APP_ALLOW_FLASH_ONCE:
Expand Down Expand Up @@ -367,10 +342,16 @@ const tabsReducer = (state, action, immutableAction) => {
const dragData = state.get('dragData')
if (dragData && dragData.get('type') === dragTypes.TAB) {
const frame = dragData.get('data')
const frameOpts = frameOptsFromFrame(frame).toJS()
let frameOpts = frameOptsFromFrame(frame)
const browserOpts = { positionByMouseCursor: true }
frameOpts.indexByFrameKey = dragData.getIn(['dragOverData', 'draggingOverKey'])
frameOpts.prependIndexByFrameKey = dragData.getIn(['dragOverData', 'draggingOverLeftHalf'])
const tabIdForIndex = dragData.getIn(['dragOverData', 'draggingOverKey'])
const tabForIndex = tabState.getByTabId(state, tabIdForIndex)
const dropWindowId = dragData.get('dropWindowId')
if (dropWindowId != null && dropWindowId !== -1 && tabForIndex) {
const prependIndexByTabId = dragData.getIn(['dragOverData', 'draggingOverLeftHalf'])
frameOpts = frameOpts.set('index', tabForIndex.get('index') + (prependIndexByTabId ? 0 : 1))
}

tabs.moveTo(state, frame.get('tabId'), frameOpts, browserOpts, dragData.get('dropWindowId'))
}
break
Expand Down
9 changes: 7 additions & 2 deletions app/browser/reducers/windowsReducer.js
Original file line number Diff line number Diff line change
Expand Up @@ -299,18 +299,23 @@ const windowsReducer = (state, action, immutableAction) => {
}
break
case appConstants.APP_CLOSE_WINDOW:
state = windows.closeWindow(state, action.get('windowId'))
windows.closeWindow(action.get('windowId'))
break
case appConstants.APP_WINDOW_CLOSED:
state = windowState.removeWindow(state, action)
sessionStoreShutdown.removeWindowFromCache(action.getIn(['windowValue', 'windowId']))
const windowId = action.getIn(['windowValue', 'windowId'])
sessionStoreShutdown.removeWindowFromCache(windowId)
windows.cleanupWindow(windowId)
break
case appConstants.APP_WINDOW_CREATED:
state = windowState.maybeCreateWindow(state, action)
break
case appConstants.APP_WINDOW_UPDATED:
state = windowState.maybeCreateWindow(state, action)
break
case appConstants.APP_TAB_STRIP_EMPTY:
windows.closeWindow(action.get('windowId'))
break
case appConstants.APP_DEFAULT_WINDOW_PARAMS_CHANGED:
if (action.get('size')) {
state = state.setIn(['defaultWindowParams', 'width'], action.getIn(['size', 0]))
Expand Down
Loading

0 comments on commit 5805ca0

Please sign in to comment.