Skip to content

Commit

Permalink
backport #941 (#947)
Browse files Browse the repository at this point in the history
  • Loading branch information
avatus authored Jul 1, 2022
1 parent 5aabf5c commit d28f4e8
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 0 deletions.
18 changes: 18 additions & 0 deletions web/packages/teleterm/src/ui/TabHost/useTabShortcuts.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -186,6 +186,15 @@ test('close active tab', () => {
expect(docsService.close).toHaveBeenCalledWith(documentToClose.uri);
});

test('do not switch tabs if tabs do not exist', () => {
const { emitKeyboardShortcutEvent, docsService } = getTestSetup({
documents: [],
});
emitKeyboardShortcutEvent({ type: 'tab-next' });

expect(docsService.open).not.toHaveBeenCalled();
});

test('open new tab', () => {
const { emitKeyboardShortcutEvent, docsService } = getTestSetup({
documents: [],
Expand Down Expand Up @@ -259,4 +268,13 @@ describe('open next/previous tab', () => {
docsService.getDocuments()[docsService.getDocuments().length - 1].uri
);
});

test('do not switch tabs if tabs do not exist', () => {
const { emitKeyboardShortcutEvent, docsService } = getTestSetup({
documents: [],
});
emitKeyboardShortcutEvent({ type: 'tab-next' });

expect(docsService.open).not.toHaveBeenCalled();
});
});
5 changes: 5 additions & 0 deletions web/packages/teleterm/src/ui/TabHost/useTabShortcuts.ts
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,11 @@ function buildTabsShortcuts(
const handleTabSwitch = (direction: 'previous' | 'next') => () => {
const activeDoc = documentService.getActive();
const allDocuments = documentService.getDocuments();

if (allDocuments.length === 0) {
return;
}

const activeDocIndex = allDocuments.indexOf(activeDoc);
const getPreviousIndex = () =>
(activeDocIndex - 1 + allDocuments.length) % allDocuments.length;
Expand Down

0 comments on commit d28f4e8

Please sign in to comment.