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

Use muon's tab_strip_model for driving index and active #10572

Closed
wants to merge 1 commit into from
Closed
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
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,62 +21,8 @@ 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 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 @@ -125,7 +70,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 @@ -153,6 +114,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 @@ -189,7 +151,7 @@ const tabsReducer = (state, action, immutableAction) => {
tabs.closeTab(tabId, action.get('forceClosePinned'))
})
} else {
state = windows.closeWindow(state, windowId)
windows.closeWindow(windowId)
}
}
}
Expand All @@ -201,8 +163,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 @@ -362,10 +337,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 @@ -28,18 +28,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