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

Commit 5805ca0

Browse files
committed
Use muon's tab_strip_model for driving index and active
Fix #10436 Fix #9385 Fix #9722 Fix #10561 Fix #9083 Fix #9671 Fix #10038 Fix #10384 Fix #10532 and probably several others.
1 parent 12cd539 commit 5805ca0

File tree

19 files changed

+361
-226
lines changed

19 files changed

+361
-226
lines changed

app/browser/reducers/tabsReducer.js

+42-61
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@ const windows = require('../windows')
1111
const {getWebContents} = require('../webContentsCache')
1212
const {BrowserWindow} = require('electron')
1313
const tabState = require('../../common/state/tabState')
14-
const windowState = require('../../common/state/windowState')
1514
const tabActions = require('../../common/actions/tabActions')
1615
const siteSettings = require('../../../js/state/siteSettings')
1716
const siteSettingsState = require('../../common/state/siteSettingsState')
@@ -22,63 +21,9 @@ const {getFlashResourceId} = require('../../../js/flash')
2221
const {l10nErrorText} = require('../../common/lib/httpUtil')
2322
const Immutable = require('immutable')
2423
const dragTypes = require('../../../js/constants/dragTypes')
25-
const getSetting = require('../../../js/settings').getSetting
26-
const settings = require('../../../js/constants/settings')
27-
const {tabCloseAction} = require('../../common/constants/settingsEnums')
2824
const {frameOptsFromFrame} = require('../../../js/state/frameStateUtil')
2925
const {isSourceAboutUrl, isTargetAboutUrl, isNavigatableAboutPage} = require('../../../js/lib/appUrlUtil')
3026

31-
const updateActiveTab = (state, closeTabId) => {
32-
if (!tabState.getByTabId(state, closeTabId)) {
33-
return
34-
}
35-
36-
const index = tabState.getIndex(state, closeTabId)
37-
if (index === -1) {
38-
return
39-
}
40-
41-
const windowId = tabState.getWindowId(state, closeTabId)
42-
if (windowId === windowState.WINDOW_ID_NONE) {
43-
return
44-
}
45-
46-
const lastActiveTabId = tabState.getTabsByLastActivated(state, windowId).last()
47-
if (lastActiveTabId !== closeTabId && !tabState.isActive(state, closeTabId)) {
48-
return
49-
}
50-
51-
let nextTabId = tabState.TAB_ID_NONE
52-
switch (getSetting(settings.TAB_CLOSE_ACTION)) {
53-
case tabCloseAction.LAST_ACTIVE:
54-
nextTabId = tabState.getLastActiveTabId(state, windowId)
55-
break
56-
case tabCloseAction.PARENT:
57-
{
58-
const openerTabId = tabState.getOpenerTabId(state, closeTabId)
59-
if (openerTabId !== tabState.TAB_ID_NONE) {
60-
nextTabId = openerTabId
61-
}
62-
break
63-
}
64-
}
65-
66-
// DEFAULT: always fall back to NEXT
67-
if (nextTabId === tabState.TAB_ID_NONE) {
68-
nextTabId = tabState.getNextTabIdByIndex(state, windowId, index)
69-
if (nextTabId === tabState.TAB_ID_NONE) {
70-
// no unpinned tabs so find the next pinned tab
71-
nextTabId = tabState.getNextTabIdByIndex(state, windowId, index, true)
72-
}
73-
}
74-
75-
if (nextTabId !== tabState.TAB_ID_NONE) {
76-
setImmediate(() => {
77-
tabs.setActive(nextTabId)
78-
})
79-
}
80-
}
81-
8227
const WEBRTC_DEFAULT = 'default'
8328
const WEBRTC_DISABLE_NON_PROXY = 'disable_non_proxied_udp'
8429

@@ -126,7 +71,23 @@ const tabsReducer = (state, action, immutableAction) => {
12671
case appConstants.APP_TAB_CREATED:
12772
state = tabState.maybeCreateTab(state, action)
12873
break
129-
case appConstants.APP_TAB_MOVED: {
74+
case appConstants.APP_TAB_ATTACHED:
75+
tabs.updateTabsStateForAttachedTab(state, action.get('tabId'))
76+
break
77+
case appConstants.APP_TAB_WILL_ATTACH: {
78+
const tabId = action.get('tabId')
79+
const tabValue = tabState.getByTabId(state, tabId)
80+
if (!tabValue) {
81+
break
82+
}
83+
const oldWindowId = tabState.getWindowId(state, tabId)
84+
tabs.updateTabsStateForWindow(state, oldWindowId)
85+
break
86+
}
87+
case appConstants.APP_TAB_MOVED:
88+
tabs.updateTabsStateForAttachedTab(state, action.get('tabId'))
89+
break
90+
case appConstants.APP_TAB_DETACH_MENU_ITEM_CLICKED: {
13091
setImmediate(() => {
13192
const tabId = action.get('tabId')
13293
const frameOpts = frameOptsFromFrame(action.get('frameOpts'))
@@ -158,6 +119,7 @@ const tabsReducer = (state, action, immutableAction) => {
158119
break
159120
case appConstants.APP_TAB_UPDATED:
160121
state = tabState.maybeCreateTab(state, action)
122+
// tabs.debugTabs(state)
161123
break
162124
case appConstants.APP_TAB_CLOSE_REQUESTED:
163125
{
@@ -194,7 +156,7 @@ const tabsReducer = (state, action, immutableAction) => {
194156
tabs.closeTab(tabId, action.get('forceClosePinned'))
195157
})
196158
} else {
197-
state = windows.closeWindow(state, windowId)
159+
windows.closeWindow(windowId)
198160
}
199161
}
200162
}
@@ -206,8 +168,21 @@ const tabsReducer = (state, action, immutableAction) => {
206168
if (tabId === tabState.TAB_ID_NONE) {
207169
break
208170
}
209-
updateActiveTab(state, tabId)
171+
const nextActiveTabId = tabs.getNextActiveTab(state, tabId)
172+
173+
// Must be called before tab is removed
174+
// But still check for no tabId because on tab detach there's a dummy tabId
175+
const tabValue = tabState.getByTabId(state, tabId)
176+
if (tabValue) {
177+
const windowIdOfTabBeingRemoved = tabState.getWindowId(state, tabId)
178+
tabs.updateTabsStateForWindow(state, windowIdOfTabBeingRemoved)
179+
}
210180
state = tabState.removeTabByTabId(state, tabId)
181+
setImmediate(() => {
182+
if (nextActiveTabId !== tabState.TAB_ID_NONE) {
183+
tabs.setActive(nextActiveTabId)
184+
}
185+
})
211186
}
212187
break
213188
case appConstants.APP_ALLOW_FLASH_ONCE:
@@ -367,10 +342,16 @@ const tabsReducer = (state, action, immutableAction) => {
367342
const dragData = state.get('dragData')
368343
if (dragData && dragData.get('type') === dragTypes.TAB) {
369344
const frame = dragData.get('data')
370-
const frameOpts = frameOptsFromFrame(frame).toJS()
345+
let frameOpts = frameOptsFromFrame(frame)
371346
const browserOpts = { positionByMouseCursor: true }
372-
frameOpts.indexByFrameKey = dragData.getIn(['dragOverData', 'draggingOverKey'])
373-
frameOpts.prependIndexByFrameKey = dragData.getIn(['dragOverData', 'draggingOverLeftHalf'])
347+
const tabIdForIndex = dragData.getIn(['dragOverData', 'draggingOverKey'])
348+
const tabForIndex = tabState.getByTabId(state, tabIdForIndex)
349+
const dropWindowId = dragData.get('dropWindowId')
350+
if (dropWindowId != null && dropWindowId !== -1 && tabForIndex) {
351+
const prependIndexByTabId = dragData.getIn(['dragOverData', 'draggingOverLeftHalf'])
352+
frameOpts = frameOpts.set('index', tabForIndex.get('index') + (prependIndexByTabId ? 0 : 1))
353+
}
354+
374355
tabs.moveTo(state, frame.get('tabId'), frameOpts, browserOpts, dragData.get('dropWindowId'))
375356
}
376357
break

app/browser/reducers/windowsReducer.js

+7-2
Original file line numberDiff line numberDiff line change
@@ -299,18 +299,23 @@ const windowsReducer = (state, action, immutableAction) => {
299299
}
300300
break
301301
case appConstants.APP_CLOSE_WINDOW:
302-
state = windows.closeWindow(state, action.get('windowId'))
302+
windows.closeWindow(action.get('windowId'))
303303
break
304304
case appConstants.APP_WINDOW_CLOSED:
305305
state = windowState.removeWindow(state, action)
306-
sessionStoreShutdown.removeWindowFromCache(action.getIn(['windowValue', 'windowId']))
306+
const windowId = action.getIn(['windowValue', 'windowId'])
307+
sessionStoreShutdown.removeWindowFromCache(windowId)
308+
windows.cleanupWindow(windowId)
307309
break
308310
case appConstants.APP_WINDOW_CREATED:
309311
state = windowState.maybeCreateWindow(state, action)
310312
break
311313
case appConstants.APP_WINDOW_UPDATED:
312314
state = windowState.maybeCreateWindow(state, action)
313315
break
316+
case appConstants.APP_TAB_STRIP_EMPTY:
317+
windows.closeWindow(action.get('windowId'))
318+
break
314319
case appConstants.APP_DEFAULT_WINDOW_PARAMS_CHANGED:
315320
if (action.get('size')) {
316321
state = state.setIn(['defaultWindowParams', 'width'], action.getIn(['size', 0]))

0 commit comments

Comments
 (0)