diff --git a/src/editor/Editor.test.tsx b/src/editor/Editor.test.tsx
index 9d6541fc..eb8fc371 100644
--- a/src/editor/Editor.test.tsx
+++ b/src/editor/Editor.test.tsx
@@ -13,7 +13,7 @@ import { editorActivateFile, editorCloseFile } from './actions';
describe('Editor', () => {
describe('tabs', () => {
- it('should dispatch action when tab is clicked', async () => {
+ it('should dispatch activate action when tab is clicked', async () => {
const [editor, dispatch] = testRender(, {
editor: { openFiles: ['test.file'] },
});
@@ -23,7 +23,23 @@ describe('Editor', () => {
expect(dispatch).toHaveBeenCalledWith(editorActivateFile('test.file'));
});
- it('should dispatch action when close button is clicked', async () => {
+ it.each(['enter', 'space'])(
+ 'should dispatch activate action when % button is pressed',
+ async (button) => {
+ const [editor, dispatch] = testRender(, {
+ editor: { openFiles: ['test.file'] },
+ });
+
+ userEvent.type(
+ editor.getByRole('tab', { name: 'test.file' }),
+ `{${button}}`,
+ );
+
+ expect(dispatch).toHaveBeenCalledWith(editorActivateFile('test.file'));
+ },
+ );
+
+ it('should dispatch close action when close button is clicked', async () => {
const [editor, dispatch] = testRender(, {
editor: { openFiles: ['test.file'] },
});
@@ -32,6 +48,16 @@ describe('Editor', () => {
expect(dispatch).toHaveBeenCalledWith(editorCloseFile('test.file'));
});
+
+ it('should dispatch close action when delete button is pressed', async () => {
+ const [editor, dispatch] = testRender(, {
+ editor: { openFiles: ['test.file'] },
+ });
+
+ userEvent.type(editor.getByRole('tab', { name: 'test.file' }), '{delete}');
+
+ expect(dispatch).toHaveBeenCalledWith(editorCloseFile('test.file'));
+ });
});
describe('context menu', () => {
diff --git a/src/editor/Editor.tsx b/src/editor/Editor.tsx
index 9d4ca65c..73c6da7a 100644
--- a/src/editor/Editor.tsx
+++ b/src/editor/Editor.tsx
@@ -13,6 +13,7 @@ import {
Tab,
TabId,
Tabs,
+ Text,
} from '@blueprintjs/core';
import { ContextMenu2, ResizeSensor2 } from '@blueprintjs/popover2';
import { I18n, useI18n } from '@shopify/react-i18n';
@@ -202,25 +203,44 @@ const EditorTabs: React.VoidFunctionComponent = ({
const labelId = useUniqueId('pb-editor');
+ // close tab when delete key is pressed
+ const handleKeyDown = useCallback(
+ (e: React.KeyboardEvent, fileName: string) => {
+ if (e.key === 'Delete') {
+ dispatch(editorCloseFile(fileName));
+ e.preventDefault();
+ e.stopPropagation();
+ }
+ },
+ [dispatch],
+ );
+
return (
{openFiles.map((fileName, i) => (
handleKeyDown(e, fileName)}
>
- {fileName}
+
+ {fileName}
+