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

Commit

Permalink
Merge pull request #11228 from brave/tabpages--11227
Browse files Browse the repository at this point in the history
allow tab pages to be closed w/ middle click
  • Loading branch information
bsclifton committed Oct 2, 2017
1 parent a665f37 commit 05c9e85
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 2 deletions.
32 changes: 30 additions & 2 deletions app/renderer/components/tabs/tabPage.js
Original file line number Diff line number Diff line change
Expand Up @@ -75,8 +75,34 @@ class TabPage extends React.Component {
windowActions.onTabPageContextMenu(this.props.index)
}

onClick () {
windowActions.setTabPageIndex(this.props.index)
onCloseTabPage () {
return this.props.tabPageFrames
.map(frame => appActions.tabCloseRequested(frame.get('tabId')))
}

onAuxClick (e) {
this.onClick(e)
}

onClick (e) {
e.stopPropagation()
switch (e.button) {
case 2:
// Ignore right click
return
case 1:
// Close tab page with middle click
// and eventually cancel the hover state
this.onCloseTabPage()
windowActions.setTabPageHoverState(this.props.index, false)
break
default:
windowActions.setTabPageIndex(this.props.index)
}
}

componentDidMount () {
this.tabPageNode.addEventListener('auxclick', this.onAuxClick.bind(this))
}

mergeProps (state, ownProps) {
Expand Down Expand Up @@ -107,6 +133,7 @@ class TabPage extends React.Component {

// used in other functions
props.sourceDragFromPageIndex = sourceDragFromPageIndex
props.tabPageFrames = tabPageFrames
props.isPageEmpty = tabPageFrames.isEmpty()
props.moveToFrameKey = tabPageFrames.getIn([0, 'key'])

Expand All @@ -115,6 +142,7 @@ class TabPage extends React.Component {

render () {
return <span
ref={(node) => { this.tabPageNode = node }}
data-tab-page={this.props.index}
onDragOver={this.onDragOver.bind(this)}
onMouseEnter={this.props.previewTabPage ? this.onMouseEnter : null}
Expand Down
9 changes: 9 additions & 0 deletions test/tab-components/tabPagesTest.js
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,15 @@ describe('tab pages', function () {
.waitForTextValue(activeTabTitle, 'Untitled')
})

it('closes tab page with middle click', function * () {
yield this.app.client
.click(newFrameButton)
.waitForElementCount(tabPage, 2)
.waitForExist(tabPage2 + '.active')
.middleClick(tabPage1)
.waitForElementCount(tabPage, 0)
})

it('shows no tab pages when you have only 1 page', function * () {
yield this.app.client
.waitForExist('[data-test-id="tab"][data-frame-key="1"]')
Expand Down

0 comments on commit 05c9e85

Please sign in to comment.