From 9a0ba1da6c318e74545d931ec67c67e87071285a Mon Sep 17 00:00:00 2001 From: Noah van der Aa Date: Mon, 11 Oct 2021 05:48:28 +0200 Subject: [PATCH] Add keyboard shortcut for help screen (#4315) * Add keyboard shortcut for help screen * Make escape key go back to the previous screen * Use key instead of which * Use router for navigating back * Use alt instead of cmd/ctrl --- client/components/Windows/Help.vue | 10 ++++++++++ client/js/keybinds.js | 19 ++++++++++++++++++- 2 files changed, 28 insertions(+), 1 deletion(-) diff --git a/client/components/Windows/Help.vue b/client/components/Windows/Help.vue index 95067dff..acbd11b7 100644 --- a/client/components/Windows/Help.vue +++ b/client/components/Windows/Help.vue @@ -199,6 +199,16 @@ +
+
+ Alt / + / +
+
+

Switch to the help menu.

+
+
+
Esc diff --git a/client/js/keybinds.js b/client/js/keybinds.js index daee796f..00874857 100644 --- a/client/js/keybinds.js +++ b/client/js/keybinds.js @@ -3,7 +3,7 @@ import Mousetrap from "mousetrap"; import store from "./store"; -import {switchToChannel} from "./router"; +import {switchToChannel, router, navigate} from "./router"; import isChannelCollapsed from "./helpers/isChannelCollapsed"; import isIgnoredKeybind from "./helpers/isIgnoredKeybind"; @@ -107,6 +107,17 @@ Mousetrap.bind(["alt+a"], function (e) { return false; }); +// Show the help menu. +Mousetrap.bind(["alt+/"], function (e) { + if (isIgnoredKeybind(e)) { + return true; + } + + navigate("Help"); + + return false; +}); + function jumpToChannel(targetChannel) { switchToChannel(targetChannel); @@ -156,6 +167,12 @@ const ignoredKeys = { }; document.addEventListener("keydown", (e) => { + // Allow navigating back to the previous page when on the help screen. + if (e.key === "Escape" && router.currentRoute.name === "Help") { + router.go(-1); + return; + } + // Ignore any key that uses alt modifier // Ignore keys defined above if (e.altKey || ignoredKeys[e.which]) {