Skip to content

Commit

Permalink
add setting to open new tab to right of current (default), or at end
Browse files Browse the repository at this point in the history
fixes brave#217
use constants for defaultSettings keys
  • Loading branch information
psimyn committed Mar 27, 2016
1 parent 85b9b1e commit f7e6b36
Show file tree
Hide file tree
Showing 7 changed files with 44 additions and 58 deletions.
5 changes: 4 additions & 1 deletion app/locales/en-US/preferences.l20n
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,11 @@
<paintTabs "Show tabs in page theme color">
<tabsPerTabPage "Tabs per tab page">
<showTabPreviews "Show tab previews on hover">
<openNewTab "Open new tabs">
<toTheRight "to the right">
<atTheEnd "at the end">

/* Prviacy settings page */
/* Privacy settings page */
<suggestionTypes "When using the location bar, suggest:">
<history "History">
<bookmarks "Bookmarks">
Expand Down
1 change: 1 addition & 0 deletions docs/state.md
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,7 @@ WindowStore
```javascript
{
activeFrameKey: number,
newFrameOffset: number,
previewFrameKey: number,
frames: [{
zoomLevel: number, // current frame zoom level
Expand Down
7 changes: 7 additions & 0 deletions js/about/preferences.js
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,13 @@ class TabsTab extends ImmutableComponent {
value={getSetting(settings.TABS_PER_TAB_PAGE, this.props.settings)}
onChange={changeSetting.bind(null, this.props.onChangeSetting, settings.TABS_PER_TAB_PAGE)} />
</SettingItem>
<SettingItem dataL10nId='openNewTab'>
<select value={getSetting(this.props.settings, settings.NEW_TAB_POSITION)}
onChange={changeSetting.bind(null, this.props.onChangeSetting, settings.NEW_TAB_POSITION)}>
<option data-l10n-id='toTheRight' value='right'/>
<option data-l10n-id='atTheEnd' value='end'/>
</select>
</SettingItem>
<SettingCheckbox dataL10nId='switchToNewTabs' prefKey={settings.SWITCH_TO_NEW_TABS} settings={this.props.settings} onChangeSetting={this.props.onChangeSetting}/>
<SettingCheckbox dataL10nId='paintTabs' prefKey={settings.PAINT_TABS} settings={this.props.settings} onChangeSetting={this.props.onChangeSetting}/>
<SettingCheckbox dataL10nId='showTabPreviews' prefKey={settings.SHOW_TAB_PREVIEWS} settings={this.props.settings} onChangeSetting={this.props.onChangeSetting}/>
Expand Down
30 changes: 16 additions & 14 deletions js/constants/appConfig.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
const updateHost = process.env.BRAVE_UPDATE_HOST || 'https://brave-laptop-updates.global.ssl.fastly.net'
const winUpdateHost = process.env.BRAVE_WIN_UPDATE_HOST || 'https://brave-download.global.ssl.fastly.net'
const crashURL = process.env.BRAVE_CRASH_URL || 'https://laptop-updates.brave.com/1/crashes'
const settings = require('../constants/settings')

module.exports = {
name: 'Brave',
Expand Down Expand Up @@ -60,19 +61,20 @@ module.exports = {
winBaseUrl: `${winUpdateHost}/multi-channel/releases/CHANNEL/winx64`
},
defaultSettings: {
'general.startup-mode': 'lastTime',
'general.homepage': 'https://www.brave.com',
'search.default-search-engine': './content/search/google.xml',
'tabs.switch-to-new-tabs': false,
'tabs.paint-tabs': true,
'tabs.tabs-per-tab-page': 6,
'tabs.show-tab-previews': true,
'privacy.history-suggestions': true,
'privacy.bookmark-suggestions': true,
'privacy.opened-tab-suggestions': true,
'privacy.autocomplete.history-size': 500,
'security.block-reported-sites': false,
'bookmarks.toolbar.show': false,
'privacy.do-not-track': false
[settings.STARTUP_MODE]: 'lastTime',
[settings.HOMEPAGE]: 'https://www.brave.com',
[settings.DEFAULT_SEARCH_ENGINE]: './content/search/google.xml',
[settings.SWITCH_TO_NEW_TABS]: false,
[settings.PAINT_TABS]: true,
[settings.NEW_TAB_POSITION]: 'right',
[settings.TABS_PER_TAB_PAGE]: 6,
[settings.SHOW_TAB_PREVIEWS]: true,
[settings.HISTORY_SUGGESTIONS]: true,
[settings.BOOKMARK_SUGGESTIONS]: true,
[settings.OPENED_TAB_SUGGESTIONS]: true,
[settings.AUTOCOMPLETE_HISTORY_SIZE]: 500,
[settings.BLOCK_REPORTED_SITES]: false,
[settings.SHOW_BOOKMARKS_TOOLBAR]: false,
[settings.DO_NOT_TRACK]: false
}
}
2 changes: 1 addition & 1 deletion js/constants/settings.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ const settings = {
PAINT_TABS: 'tabs.paint-tabs',
TABS_PER_TAB_PAGE: 'tabs.tabs-per-tab-page',
SHOW_TAB_PREVIEWS: 'tabs.show-tab-previews',
NEW_TAB_POSITION: 'tabs.new-tab-position',
// Privacy Tab
HISTORY_SUGGESTIONS: 'privacy.history-suggestions',
BOOKMARK_SUGGESTIONS: 'privacy.bookmark-suggestions',
Expand All @@ -26,4 +27,3 @@ const settings = {
}

module.exports = settings

49 changes: 9 additions & 40 deletions js/state/frameStateUtil.js
Original file line number Diff line number Diff line change
Expand Up @@ -112,43 +112,11 @@ export function getFeatures (featureStr) {
}, {})
}

/**
* Determines if the specified frame was opened from the specified
* ancestorFrameKey.
*
* For example you may go to google.com and open 3 links in new tabs:
* G g1 g2 g3
* Then you may change to g1 and open another tab:
* G g1 g1.1 g2 g3
* But then you may go back to google.com and open another tab.
* It should go like so:
* G g1 g1.1 g2 g3 g4
*/
function isAncestorFrameKey (frames, frame, parentFrameKey) {
if (!frame || !frame.get('parentFrameKey')) {
return false
}

if (frame.get('parentFrameKey') === parentFrameKey) {
return true
}

// So there is a parentFrameKey but it isn't the specified one.
// Check recursively for each of the parentFrame's ancestors to see
// if we have a match.
const parentFrameIndex = findIndexForFrameKey(frames, frame.get('parentFrameKey'))
const parentFrame = frames.get(parentFrameIndex)
if (parentFrameIndex === -1 || !parentFrame.get('parentFrameKey')) {
return false
}
return isAncestorFrameKey(frames, parentFrame, parentFrameKey)
}

/**
* Adds a frame specified by frameOpts and newKey and sets the activeFrameKey
* @return Immutable top level application state ready to merge back in
*/
export function addFrame (frames, frameOpts, newKey, partitionNumber, activeFrameKey) {
export function addFrame (frames, frameOpts, newKey, partitionNumber, activeFrameKey, newFrameOffset) {
const url = frameOpts.location || config.defaultUrl
const navbarFocus = activeFrameKey === newKey &&
url === config.defaultUrl &&
Expand Down Expand Up @@ -200,21 +168,22 @@ export function addFrame (frames, frameOpts, newKey, partitionNumber, activeFram
})

// Find the closest index to the current frame's index which has
// a different ancestor frame key.
let insertionIndex = findIndexForFrameKey(frames, frameOpts.parentFrameKey)
if (insertionIndex === -1) {
insertionIndex = frames.size
}
while (insertionIndex < frames.size) {
++insertionIndex
if (!isAncestorFrameKey(frames, frames.get(insertionIndex), frameOpts.parentFrameKey)) {
break
} else {
if (newKey === activeFrameKey) {
newFrameOffset = 0
} else {
newFrameOffset++
}
insertionIndex += newFrameOffset
}

return {
frames: frames.splice(insertionIndex, 0, frame),
activeFrameKey
activeFrameKey,
newFrameOffset
}
}

Expand Down
8 changes: 6 additions & 2 deletions js/stores/windowStore.js
Original file line number Diff line number Diff line change
Expand Up @@ -220,8 +220,11 @@ const doAction = (action) => {
} else if (action.frameOpts.isPartitioned) {
nextPartitionNumber = incrementPartitionNumber()
}
if (!action.frameOpts.parentFrameKey && getSetting(settings.NEW_TAB_POSITION) === 'right') {
action.frameOpts.parentFrameKey = windowState.get('activeFrameKey')
}
windowState = windowState.merge(FrameStateUtil.addFrame(windowState.get('frames'), action.frameOpts,
nextKey, nextPartitionNumber, action.openInForeground ? nextKey : windowState.get('activeFrameKey')))
nextKey, nextPartitionNumber, action.openInForeground ? nextKey : windowState.get('activeFrameKey'), windowState.get('newFrameOffset')))
if (action.openInForeground) {
updateTabPageIndex(FrameStateUtil.getActiveFrame(windowState))
}
Expand All @@ -244,7 +247,8 @@ const doAction = (action) => {
case WindowConstants.WINDOW_SET_ACTIVE_FRAME:
windowState = windowState.merge({
activeFrameKey: action.frameProps.get('key'),
previewFrameKey: null
previewFrameKey: null,
newFrameOffset: 0
})
updateTabPageIndex(action.frameProps)
break
Expand Down

0 comments on commit f7e6b36

Please sign in to comment.