Skip to content

Commit ab62ccf

Browse files
authored
Allow tab closing with middle mouse button (codesandbox#355)
* Allow tab closing with middle mouse button * Don't allow closing tabs with 1 tab.
1 parent eda49ff commit ab62ccf

File tree

2 files changed

+12
-0
lines changed
  • packages/app/src/app

2 files changed

+12
-0
lines changed

packages/app/src/app/components/sandbox/CodeEditor/Tabs/Tab.js

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -113,6 +113,13 @@ export default class Tab extends React.PureComponent<Props, State> {
113113
});
114114
};
115115

116+
onMouseDown = (e: MouseEvent) => {
117+
if (e.button === 1) {
118+
// Middle mouse button
119+
this.closeTab(e);
120+
}
121+
};
122+
116123
closeTab = (e: MouseEvent) => {
117124
e.preventDefault();
118125
e.stopPropagation();
@@ -143,6 +150,7 @@ export default class Tab extends React.PureComponent<Props, State> {
143150
isOver={isOver}
144151
onClick={onClick}
145152
onDoubleClick={onDoubleClick}
153+
onMouseDown={this.onMouseDown}
146154
onMouseEnter={this.handleMouseEnter}
147155
onMouseLeave={this.handleMouseLeave}
148156
>

packages/app/src/app/store/entities/sandboxes/reducer.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,10 @@ function singleSandboxReducer(sandbox: Sandbox, action: Action): Sandbox {
9595
return newSandbox;
9696
}
9797
case CLOSE_TAB: {
98+
if (sandbox.tabs.length === 1) {
99+
return sandbox;
100+
}
101+
98102
const tabPos = action.position;
99103
let currentModule = sandbox.currentModule;
100104
const tabModuleId = sandbox.tabs[tabPos].moduleId;

0 commit comments

Comments
 (0)