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

Commit

Permalink
fix bad tab page preview while closing tabs
Browse files Browse the repository at this point in the history
fix #11632
  • Loading branch information
cezaraugusto committed Nov 2, 2017
1 parent e02bafd commit 4355858
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 36 deletions.
12 changes: 0 additions & 12 deletions js/actions/windowActions.js
Original file line number Diff line number Diff line change
Expand Up @@ -273,18 +273,6 @@ const windowActions = {
})
},

/**
* Dispatches a message to the store to set the tab page index being previewed.
*
* @param {number} previewTabPageIndex - The tab page index to preview
*/
setPreviewTabPageIndex: function (previewTabPageIndex) {
dispatch({
actionType: windowConstants.WINDOW_SET_PREVIEW_TAB_PAGE_INDEX,
previewTabPageIndex
})
},

/**
* Dispatches a message to the store to set the tab page index.
*
Expand Down
27 changes: 3 additions & 24 deletions js/state/frameStateUtil.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ const {getSetting} = require('../settings')
const {isIntermediateAboutPage} = require('../lib/appUrlUtil')
const urlParse = require('../../app/common/urlParse')

let tabPageHoverTimeout
let tabHoverTimeout = null

const comparatorByKeyAsc = (a, b) => a.get('key') > b.get('key')
Expand Down Expand Up @@ -584,36 +583,16 @@ const getPreviewFrameKey = (state) => {
return state.get('previewFrameKey')
}

const setPreviewTabPageIndex = (state, index, immediate = false) => {
clearTimeout(tabPageHoverTimeout)
const setPreviewTabPageIndex = (state, index) => {
const previewTabs = getSetting(settings.SHOW_TAB_PREVIEWS)
const isActive = state.getIn(['ui', 'tabs', 'tabPageIndex']) === index
const hoverTabPageIndex = state.getIn(['ui', 'tabs', 'hoverTabPageIndex'])
let newTabPageIndex = index

if (!previewTabs || state.getIn(['ui', 'tabs', 'hoverTabPageIndex']) !== index || isActive) {
if (!previewTabs || hoverTabPageIndex !== index || isActive) {
newTabPageIndex = null
}

if (!immediate) {
// if there is an existing preview tab page index then we're already in preview mode
// we use actions here because that is the only way to delay updating the state
const previewMode = state.getIn(['ui', 'tabs', 'previewTabPageIndex']) != null
if (previewMode && newTabPageIndex == null) {
// add a small delay when we are clearing the preview frame key so we don't lose
// previewMode if the user mouses over another tab - see below
tabPageHoverTimeout = setTimeout(windowActions.setPreviewTabPageIndex.bind(null, null), 200)
return state
}

if (!previewMode) {
// If user isn't in previewMode so we add a bit of delay to avoid tab from flashing out
// as reported here: https://github.com/brave/browser-laptop/issues/1434
// using an action here because that is the only way we can do a delayed state update
tabPageHoverTimeout = setTimeout(windowActions.setPreviewTabPageIndex.bind(null, newTabPageIndex), 200)
return state
}
}

return state.setIn(['ui', 'tabs', 'previewTabPageIndex'], newTabPageIndex)
}

Expand Down

0 comments on commit 4355858

Please sign in to comment.