@@ -11,7 +11,6 @@ const windows = require('../windows')
11
11
const { getWebContents} = require ( '../webContentsCache' )
12
12
const { BrowserWindow} = require ( 'electron' )
13
13
const tabState = require ( '../../common/state/tabState' )
14
- const windowState = require ( '../../common/state/windowState' )
15
14
const tabActions = require ( '../../common/actions/tabActions' )
16
15
const siteSettings = require ( '../../../js/state/siteSettings' )
17
16
const siteSettingsState = require ( '../../common/state/siteSettingsState' )
@@ -22,63 +21,9 @@ const {getFlashResourceId} = require('../../../js/flash')
22
21
const { l10nErrorText} = require ( '../../common/lib/httpUtil' )
23
22
const Immutable = require ( 'immutable' )
24
23
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' )
28
24
const { frameOptsFromFrame} = require ( '../../../js/state/frameStateUtil' )
29
25
const { isSourceAboutUrl, isTargetAboutUrl, isNavigatableAboutPage} = require ( '../../../js/lib/appUrlUtil' )
30
26
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
-
82
27
const WEBRTC_DEFAULT = 'default'
83
28
const WEBRTC_DISABLE_NON_PROXY = 'disable_non_proxied_udp'
84
29
@@ -126,7 +71,23 @@ const tabsReducer = (state, action, immutableAction) => {
126
71
case appConstants . APP_TAB_CREATED :
127
72
state = tabState . maybeCreateTab ( state , action )
128
73
break
129
- case appConstants . APP_TAB_MOVED : {
74
+ case appConstants . APP_TAB_ATTACHED :
75
+ state = 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
+ state = tabs . updateTabsStateForWindow ( state , oldWindowId )
85
+ break
86
+ }
87
+ case appConstants . APP_TAB_MOVED :
88
+ state = tabs . updateTabsStateForAttachedTab ( state , action . get ( 'tabId' ) )
89
+ break
90
+ case appConstants . APP_TAB_DETACH_MENU_ITEM_CLICKED : {
130
91
setImmediate ( ( ) => {
131
92
const tabId = action . get ( 'tabId' )
132
93
const frameOpts = frameOptsFromFrame ( action . get ( 'frameOpts' ) )
@@ -158,6 +119,7 @@ const tabsReducer = (state, action, immutableAction) => {
158
119
break
159
120
case appConstants . APP_TAB_UPDATED :
160
121
state = tabState . maybeCreateTab ( state , action )
122
+ // tabs.debugTabs(state)
161
123
break
162
124
case appConstants . APP_TAB_CLOSE_REQUESTED :
163
125
{
@@ -194,7 +156,7 @@ const tabsReducer = (state, action, immutableAction) => {
194
156
tabs . closeTab ( tabId , action . get ( 'forceClosePinned' ) )
195
157
} )
196
158
} else {
197
- state = windows . closeWindow ( state , windowId )
159
+ windows . closeWindow ( windowId )
198
160
}
199
161
}
200
162
}
@@ -206,8 +168,21 @@ const tabsReducer = (state, action, immutableAction) => {
206
168
if ( tabId === tabState . TAB_ID_NONE ) {
207
169
break
208
170
}
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
+ state = tabs . updateTabsStateForWindow ( state , windowIdOfTabBeingRemoved )
179
+ }
210
180
state = tabState . removeTabByTabId ( state , tabId )
181
+ setImmediate ( ( ) => {
182
+ if ( nextActiveTabId !== tabState . TAB_ID_NONE ) {
183
+ tabs . setActive ( nextActiveTabId )
184
+ }
185
+ } )
211
186
}
212
187
break
213
188
case appConstants . APP_ALLOW_FLASH_ONCE :
@@ -225,9 +200,7 @@ const tabsReducer = (state, action, immutableAction) => {
225
200
} )
226
201
break
227
202
case appConstants . APP_TAB_PINNED :
228
- setImmediate ( ( ) => {
229
- tabs . pin ( state , action . get ( 'tabId' ) , action . get ( 'pinned' ) )
230
- } )
203
+ state = tabs . pin ( state , action . get ( 'tabId' ) , action . get ( 'pinned' ) )
231
204
break
232
205
case windowConstants . WINDOW_SET_AUDIO_MUTED :
233
206
setImmediate ( ( ) => {
@@ -372,10 +345,15 @@ const tabsReducer = (state, action, immutableAction) => {
372
345
const dragData = state . get ( 'dragData' )
373
346
if ( dragData && dragData . get ( 'type' ) === dragTypes . TAB ) {
374
347
const frame = dragData . get ( 'data' )
375
- const frameOpts = frameOptsFromFrame ( frame ) . toJS ( )
348
+ let frameOpts = frameOptsFromFrame ( frame )
376
349
const browserOpts = { positionByMouseCursor : true , checkMaximized : true }
377
- frameOpts . indexByFrameKey = dragData . getIn ( [ 'dragOverData' , 'draggingOverKey' ] )
378
- frameOpts . prependIndexByFrameKey = dragData . getIn ( [ 'dragOverData' , 'draggingOverLeftHalf' ] )
350
+ const tabIdForIndex = dragData . getIn ( [ 'dragOverData' , 'draggingOverKey' ] )
351
+ const tabForIndex = tabState . getByTabId ( state , tabIdForIndex )
352
+ const dropWindowId = dragData . get ( 'dropWindowId' )
353
+ if ( dropWindowId != null && dropWindowId !== - 1 && tabForIndex ) {
354
+ const prependIndexByTabId = dragData . getIn ( [ 'dragOverData' , 'draggingOverLeftHalf' ] )
355
+ frameOpts = frameOpts . set ( 'index' , tabForIndex . get ( 'index' ) + ( prependIndexByTabId ? 0 : 1 ) )
356
+ }
379
357
tabs . moveTo ( state , frame . get ( 'tabId' ) , frameOpts , browserOpts , dragData . get ( 'dropWindowId' ) )
380
358
}
381
359
break
0 commit comments