mirror of
https://github.com/thelounge/thelounge
synced 2024-11-14 00:07:17 +00:00
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
This commit is contained in:
parent
2ab671664e
commit
9a0ba1da6c
2 changed files with 28 additions and 1 deletions
|
@ -199,6 +199,16 @@
|
|||
</div>
|
||||
</div>
|
||||
|
||||
<div class="help-item">
|
||||
<div class="subject">
|
||||
<span v-if="!isApple"><kbd>Alt</kbd> <kbd>/</kbd></span>
|
||||
<span v-else><kbd>⌥</kbd> <kbd>/</kbd></span>
|
||||
</div>
|
||||
<div class="description">
|
||||
<p>Switch to the help menu.</p>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="help-item">
|
||||
<div class="subject">
|
||||
<span><kbd>Esc</kbd></span>
|
||||
|
|
|
@ -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]) {
|
||||
|
|
Loading…
Reference in a new issue