Skip to content

Commit 4130170

Browse files
author
Ives van Hoorne
committed
Add 'Close Current Tab' keybinding
1 parent f80bed8 commit 4130170

File tree

2 files changed

+12
-17
lines changed

2 files changed

+12
-17
lines changed

packages/app/src/app/pages/Sandbox/Editor/Content/Tabs/index.js

Lines changed: 0 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -15,13 +15,6 @@ import {
1515
} from './elements';
1616

1717
class EditorTabs extends React.Component {
18-
componentWillMount() {
19-
window.addEventListener('keydown', this.closeListener);
20-
}
21-
componentWillUnmount() {
22-
window.removeEventListener('keydown', this.closeListener);
23-
}
24-
2518
componentDidUpdate(prevProps) {
2619
if (this.props.currentModuleId !== prevProps.currentModuleId) {
2720
// We need to scroll to the tab
@@ -42,16 +35,6 @@ class EditorTabs extends React.Component {
4235
}
4336
}
4437

45-
closeListener = e => {
46-
if ((e.ctrlKey || e.metaKey) && e.keyCode === 87) {
47-
e.preventDefault();
48-
const currentPos = this.props.tabs
49-
.filter(x => x)
50-
.findIndex(t => t.moduleId === this.props.currentModuleId);
51-
this.closeTab(currentPos);
52-
}
53-
};
54-
5538
closeTab = tabIndex => {
5639
this.props.signals.editor.tabClosed({ tabIndex });
5740
};

packages/common/utils/keybindings.js

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,18 @@ export const KEYBINDINGS = {
5353
signal: 'workspace.toggleCurrentWorkspaceItem',
5454
},
5555

56+
'editor.close-tab': {
57+
title: 'Close Current Tab',
58+
type: 'View',
59+
bindings: [['Control', 'W']],
60+
signal: 'editor.tabClosed',
61+
payload: state => ({
62+
tabIndex: state.editor.tabs
63+
.filter(x => x)
64+
.findIndex(t => t.moduleId === state.currentModuleId),
65+
}),
66+
},
67+
5668
'editor.zen-mode': {
5769
title: 'Toggle Zen Mode',
5870
type: 'View',

0 commit comments

Comments
 (0)