This commit is contained in:
Gabor Szabo 2025-04-02 18:48:25 +03:00 committed by Eric Huss
parent 2b455fcd34
commit c9ad6dbf10

View file

@ -644,36 +644,38 @@ aria-label="Show hidden lines"></button>';
} }
} }
function showHelp() { function showHelp() {
document.getElementById("help-overlay").style.display = "block"; document.getElementById('help-overlay').style.display = 'block';
let help = `<h2 id="help-title">Keyboard shortcuts</h2>`; let help = '<h2 id="help-title">Keyboard shortcuts</h2>';
help += "<p>Press <kbd>←</kbd> or <kbd>→</kbd> to navigate between chapters</p>"; help += '<p>Press <kbd>←</kbd> or <kbd>→</kbd> to navigate between chapters</p>';
help += "<p>Press <kbd>s</kbd> to search in the book</p>"; help += '<p>Press <kbd>s</kbd> to search in the book</p>';
help += "<p>Press <kbd>?</kbd> to show this help</p>"; help += '<p>Press <kbd>?</kbd> to show this help</p>';
help += "<p>Press <kbd>Esc</kbd> to hide this help</p>"; help += '<p>Press <kbd>Esc</kbd> to hide this help</p>';
document.getElementById("help-overlay").innerHTML = help; document.getElementById('help-overlay').innerHTML = help;
document.addEventListener('keydown', function (e) { document.addEventListener('keydown', function(e) {
if (e.altKey || e.ctrlKey || e.metaKey || e.shiftKey) { return; } if (e.altKey || e.ctrlKey || e.metaKey || e.shiftKey) {
return;
}
switch (e.key) { switch (e.key) {
case 'Escape': case 'Escape':
e.preventDefault(); e.preventDefault();
hideHelp(); hideHelp();
break; break;
} }
}); });
} }
function hideHelp() { function hideHelp() {
document.getElementById("help-overlay").style.display = "none"; document.getElementById('help-overlay').style.display = 'none';
} }
// Usually needs the Shift key to be pressed // Usually needs the Shift key to be pressed
switch (e.key) { switch (e.key) {
case '?': case '?':
e.preventDefault(); e.preventDefault();
showHelp(); showHelp();
break; break;
} }
// Rest of the keys are only active when the Shift key is not pressed // Rest of the keys are only active when the Shift key is not pressed