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

Active tab update issue master #9057

Merged
merged 7 commits into from
May 25, 2017
Merged
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
4 changes: 2 additions & 2 deletions .npmrc
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
runtime = electron
target_arch = x64
brave_electron_version = 3.0.200
brave_electron_version = 3.0.201
chromedriver_version = 2.27
target = v3.0.200
target = v3.0.201
disturl=https://brave-laptop-binaries.s3.amazonaws.com/atom-shell/dist/
build_from_source = true
83 changes: 78 additions & 5 deletions app/browser/reducers/tabsReducer.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,18 +6,79 @@

const appConstants = require('../../../js/constants/appConstants')
const tabs = require('../tabs')
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 windowConstants = require('../../../js/constants/windowConstants')
const windowAction = require('../../../js/actions/windowActions.js')
const {makeImmutable} = require('../../common/state/immutableUtil')
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
}

if (!tabState.isActive(state, closeTabId)) {
return
}

const windowId = tabState.getWindowId(state, closeTabId)
if (windowId === windowState.WINDOW_ID_NONE) {
return
}

let nextTabId = tabState.TAB_ID_NONE
switch (getSetting(settings.TAB_CLOSE_ACTION)) {
case tabCloseAction.LAST_ACTIVE:
nextTabId = tabState.getLastActiveTabId(state, windowId)
break
default:
{
const openerTabId = tabState.getOpenerTabId(state, closeTabId)
const lastActiveTabId = tabState.getLastActiveTabId(state, windowId)
if (openerTabId === lastActiveTabId) {
nextTabId = openerTabId
}
break
}
}

// 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 we can't find anything else just pick the first tab
if (nextTabId === tabState.TAB_ID_NONE) {
nextTabId = tabState.getTabIdByIndex(state, windowId, 0, true)
}

if (nextTabId !== tabState.TAB_ID_NONE) {
setImmediate(() => {
tabs.setActive(nextTabId)
})
}
}

const tabsReducer = (state, action, immutableAction) => {
action = immutableAction || makeImmutable(action)
switch (action.get('actionType')) {
Expand Down Expand Up @@ -71,15 +132,26 @@ const tabsReducer = (state, action, immutableAction) => {
break
}

setImmediate(() => {
if (tabId) {
if (tabs.isDevToolsFocused(tabId)) {
if (tabId) {
if (tabs.isDevToolsFocused(tabId)) {
setImmediate(() => {
tabs.toggleDevTools(tabId)
})
} else {
const windowId = tabState.getWindowId(state, tabId)
const nonPinnedTabs = tabState.getNonPinnedTabsByWindowId(state, windowId)
const pinnedTabs = tabState.getPinnedTabsByWindowId(state, windowId)

if (nonPinnedTabs.size > 1 ||
(nonPinnedTabs.size > 0 && pinnedTabs.size > 0)) {
setImmediate(() => {
tabs.closeTab(tabId, action.get('forceClosePinned'))
})
} else {
tabs.closeTab(tabId, action.get('forceClosePinned'))
state = windows.closeWindow(state, windowId)
}
}
})
}
}
break
case appConstants.APP_TAB_CLOSED:
Expand All @@ -88,6 +160,7 @@ const tabsReducer = (state, action, immutableAction) => {
if (tabId === tabState.TAB_ID_NONE) {
break
}
updateActiveTab(state, tabId)
state = tabState.removeTabByTabId(state, tabId)
}
break
Expand Down
2 changes: 1 addition & 1 deletion app/browser/reducers/urlBarSuggestionsReducer.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ const urlBarSuggestionsReducer = (state, action) => {
case appConstants.APP_SEARCH_SUGGESTION_RESULTS_AVAILABLE:
state = state.set('searchResults', makeImmutable(action.searchResults))
if (action.query) {
const windowId = tabState.windowId(state, action.tabId)
const windowId = tabState.getWindowId(state, action.tabId)
generateNewSuggestionsList(state, windowId, action.tabId, action.query)
}
break
Expand Down
2 changes: 1 addition & 1 deletion app/browser/reducers/windowsReducer.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ const windowsReducer = (state, action, immutableAction) => {
}
break
case appConstants.APP_CLOSE_WINDOW:
state = windows.closeWindow(state, action)
state = windows.closeWindow(state, action.get('windowId'))
break
case appConstants.APP_WINDOW_CLOSED:
state = windowState.removeWindow(state, action)
Expand Down
4 changes: 1 addition & 3 deletions app/browser/windows.js
Original file line number Diff line number Diff line change
Expand Up @@ -324,9 +324,7 @@ const api = {
})
},

closeWindow: (state, action) => {
action = makeImmutable(action)
let windowId = action.get('windowId')
closeWindow: (state, windowId) => {
let win = api.getWindow(windowId)
try {
setImmediate(() => {
Expand Down
Loading