Skip to content

Commit

Permalink
Add keyboard shortcuts for tabs
Browse files Browse the repository at this point in the history
  • Loading branch information
zerebos committed Sep 9, 2023
1 parent c881b39 commit 15254e2
Show file tree
Hide file tree
Showing 2 changed files with 80 additions and 0 deletions.
20 changes: 20 additions & 0 deletions src/public/app/widgets/tab_row.js
Original file line number Diff line number Diff line change
Expand Up @@ -267,8 +267,28 @@ export default class TabRowWidget extends BasicWidget {
}
});
});

keyboardActionService.setupActionsForElement('tabs', $(document), this);
}

goToTab(tabNumber) {
const index = tabNumber === 0 ? this.tabEls.length - 1 : tabNumber - 1;
const tab = this.tabEls[index];
if (!tab) return;
appContext.tabManager.activateNoteContext(tab.getAttribute('data-ntx-id'));
}

firstTabCommand() {this.goToTab(1);}
secondTabCommand() {this.goToTab(2);}
thirdTabCommand() {this.goToTab(3);}
fourthTabCommand() {this.goToTab(4);}
fifthTabCommand() {this.goToTab(5);}
sixthTabCommand() {this.goToTab(6);}
seventhTabCommand() {this.goToTab(7);}
eigthTabCommand() {this.goToTab(8);}
ninthTabCommand() {this.goToTab(9);}
lastTabCommand() {this.goToTab(0);}

setupStyle() {
this.$style = $("<style>");
this.$widget.append(this.$style);
Expand Down
60 changes: 60 additions & 0 deletions src/services/keyboard_actions.js
Original file line number Diff line number Diff line change
Expand Up @@ -231,6 +231,66 @@ const DEFAULT_KEYBOARD_ACTIONS = [
description: "Open new empty window",
scope: "window"
},
{
actionName: "firstTab",
defaultShortcuts: ["CommandOrControl+1"],
description: "Activates the first tab in the list",
scope: "tabs"
},
{
actionName: "secondTab",
defaultShortcuts: ["CommandOrControl+2"],
description: "Activates the second tab in the list",
scope: "tabs"
},
{
actionName: "thirdTab",
defaultShortcuts: ["CommandOrControl+3"],
description: "Activates the third tab in the list",
scope: "tabs"
},
{
actionName: "fourthTab",
defaultShortcuts: ["CommandOrControl+4"],
description: "Activates the fourth tab in the list",
scope: "tabs"
},
{
actionName: "fifthTab",
defaultShortcuts: ["CommandOrControl+5"],
description: "Activates the fifth tab in the list",
scope: "tabs"
},
{
actionName: "sixthTab",
defaultShortcuts: ["CommandOrControl+6"],
description: "Activates the sixth tab in the list",
scope: "tabs"
},
{
actionName: "seventhTab",
defaultShortcuts: ["CommandOrControl+7"],
description: "Activates the seventh tab in the list",
scope: "tabs"
},
{
actionName: "eigthTab",
defaultShortcuts: ["CommandOrControl+8"],
description: "Activates the eigth tab in the list",
scope: "tabs"
},
{
actionName: "ninthTab",
defaultShortcuts: ["CommandOrControl+9"],
description: "Activates the ninth tab in the list",
scope: "tabs"
},
{
actionName: "lastTab",
defaultShortcuts: ["CommandOrControl+0"],
description: "Activates the last tab in the list",
scope: "tabs"
},


{
Expand Down

0 comments on commit 15254e2

Please sign in to comment.