@@ -50,6 +50,7 @@ const {hasBreakpoint} = require('../../lib/tabUtil')
50
50
class Tab extends React . Component {
51
51
constructor ( props ) {
52
52
super ( props )
53
+ this . onMouseMove = this . onMouseMove . bind ( this )
53
54
this . onMouseEnter = this . onMouseEnter . bind ( this )
54
55
this . onMouseLeave = this . onMouseLeave . bind ( this )
55
56
this . onUpdateTabSize = this . onUpdateTabSize . bind ( this )
@@ -129,27 +130,47 @@ class Tab extends React.Component {
129
130
dnd . onDragOver ( dragTypes . TAB , this . tabNode . getBoundingClientRect ( ) , this . props . frameKey , this . draggingOverData , e )
130
131
}
131
132
132
- onMouseLeave ( ) {
133
+ onMouseLeave ( e ) {
134
+ windowActions . setTabHoverState ( this . props . frameKey , false )
135
+
133
136
if ( this . props . previewTabs ) {
134
- window . clearTimeout ( this . hoverTimeout )
135
- windowActions . setPreviewFrame ( null )
137
+ clearTimeout ( this . mouseTimeout )
138
+ // Matches tab_, tabArea, tabTitle, tabId, closeTab and
139
+ // all tab icons such as favicon, private and new session
140
+ const tabComponents = / t a b (? = _ | a r e a | t i t l e | i d ) | c l o s e t a b | i c o n / i
141
+ const tabAsRelatedTarget = tabComponents . test ( e . relatedTarget . classList )
142
+
143
+ // We are taking for granted that user hovering over another tab
144
+ // means that he wants to sequentially preview a set of tabs,
145
+ // so if previewMode was set by defined mouse idle time,
146
+ // only cancel previewMode if the next event doesn't happen in another tab.
147
+ if ( ! tabAsRelatedTarget ) {
148
+ windowActions . setPreviewFrame ( null )
149
+ windowActions . setPreviewMode ( false )
150
+ }
136
151
}
137
152
windowActions . setTabHoverState ( this . props . frameKey , false )
138
153
}
139
154
140
155
onMouseEnter ( e ) {
141
- // relatedTarget inside mouseenter checks which element before this event was the pointer on
142
- // if this element has a tab-like class, then it's likely that the user was previewing
143
- // a sequency of tabs. Called here as previewMode.
144
- const previewMode = / t a b (? ! p a g e s ) / i. test ( e . relatedTarget . classList )
156
+ windowActions . setTabHoverState ( this . props . frameKey , true )
145
157
146
- // If user isn't in previewMode, we add a bit of delay to avoid tab from flashing out
147
- // as reported here: https://github.com/brave/browser-laptop/issues/1434
158
+ this . mouseTimeout = null
159
+ if ( this . props . previewTabs && this . props . previewMode ) {
160
+ windowActions . setPreviewFrame ( this . props . frameKey )
161
+ }
162
+ }
163
+
164
+ onMouseMove ( e ) {
165
+ // previewMode is only triggered if mouse is idle over a tab
166
+ // for a given amount of time based on timing defined in prefs->tabs
148
167
if ( this . props . previewTabs ) {
149
- this . hoverTimeout =
150
- window . setTimeout ( windowActions . setPreviewFrame . bind ( null , this . props . frameKey ) , previewMode ? 0 : 200 )
168
+ clearTimeout ( this . mouseTimeout )
169
+ this . mouseTimeout = setTimeout ( ( ) => {
170
+ windowActions . setPreviewFrame ( this . props . frameKey )
171
+ windowActions . setPreviewMode ( true )
172
+ } , getSetting ( settings . TAB_PREVIEW_TIMING ) )
151
173
}
152
- windowActions . setTabHoverState ( this . props . frameKey , true )
153
174
}
154
175
155
176
onAuxClick ( e ) {
@@ -272,6 +293,7 @@ class Tab extends React.Component {
272
293
props . dragData = state . getIn ( [ 'dragData' , 'type' ] ) === dragTypes . TAB && state . get ( 'dragData' )
273
294
props . hasTabInFullScreen = tabContentState . hasTabInFullScreen ( currentWindow )
274
295
props . tabId = frame . get ( 'tabId' )
296
+ props . previewMode = currentWindow . getIn ( [ 'ui' , 'tabs' , 'previewMode' ] )
275
297
276
298
return props
277
299
}
@@ -298,6 +320,7 @@ class Tab extends React.Component {
298
320
partOfFullPageSet : this . props . partOfFullPageSet || ! ! this . props . tabWidth
299
321
} ) }
300
322
style = { this . props . tabWidth ? { flex : `0 0 ${ this . props . tabWidth } px` } : { } }
323
+ onMouseMove = { this . onMouseMove }
301
324
onMouseEnter = { this . onMouseEnter }
302
325
onMouseLeave = { this . onMouseLeave } >
303
326
{
0 commit comments