Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add keyboard shortcuts for tabs #4251

Merged
merged 2 commits into from
Sep 12, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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('window', $(document), this);
}

goToTab(tabNumber) {
const index = tabNumber === Number.POSITIVE_INFINITY ? 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(Number.POSITIVE_INFINITY);}

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: "window"
},
{
actionName: "secondTab",
defaultShortcuts: ["CommandOrControl+2"],
description: "Activates the second tab in the list",
scope: "window"
},
{
actionName: "thirdTab",
defaultShortcuts: ["CommandOrControl+3"],
description: "Activates the third tab in the list",
scope: "window"
},
{
actionName: "fourthTab",
defaultShortcuts: ["CommandOrControl+4"],
description: "Activates the fourth tab in the list",
scope: "window"
},
{
actionName: "fifthTab",
defaultShortcuts: ["CommandOrControl+5"],
description: "Activates the fifth tab in the list",
scope: "window"
},
{
actionName: "sixthTab",
defaultShortcuts: ["CommandOrControl+6"],
description: "Activates the sixth tab in the list",
scope: "window"
},
{
actionName: "seventhTab",
defaultShortcuts: ["CommandOrControl+7"],
description: "Activates the seventh tab in the list",
scope: "window"
},
{
actionName: "eigthTab",
defaultShortcuts: ["CommandOrControl+8"],
description: "Activates the eigth tab in the list",
scope: "window"
},
{
actionName: "ninthTab",
defaultShortcuts: ["CommandOrControl+9"],
description: "Activates the ninth tab in the list",
scope: "window"
},
{
actionName: "lastTab",
defaultShortcuts: ["CommandOrControl+0"],
description: "Activates the last tab in the list",
scope: "window"
},


{
Expand Down
Loading