Add keyboard shortcut help and improved navigation controls
Build and push image / deploy (push) Canceled after 0s

- Introduced a modal to display keyboard shortcuts with a toggle button (`?`) in the interface.
- Added support for toggling shortcuts list visibility via `?` and `Escape` keys.
- Enabled navigation with additional shortcuts: `n/p`, `Home/End`, `m`, and `Space/Shift+Space` for improved usability.
- Modified keypress handling to accommodate new shortcuts while preventing default browser scroll actions where necessary.
- Updated styles to ensure proper positioning and accessibility of the shortcut list.
This commit is contained in:
ajurna committed 2026-10-16 09:41:45 +01:00
1 parent 80566e657e
commit bb47478511
2 files changed
+200 -4

No files matched your search

+108 -4
View File
@@ -46,6 +46,29 @@
@nextComic="nextComic"
/>
</div>
<div class="col-auto">
<button
type="button"
class="btn btn-sm btn-outline-secondary"
:class="{ active: show_shortcuts }"
:aria-pressed="show_shortcuts ? 'true' : 'false'"
@click="show_shortcuts = !show_shortcuts"
>?</button>
</div>
</div>
<div class="shortcuts" v-if="show_shortcuts" role="dialog" aria-label="Keyboard shortcuts">
<div class="shortcuts-head">
<strong>Keyboard shortcuts</strong>
<button type="button" class="btn btn-sm btn-outline-secondary" @click="show_shortcuts = false">Close</button>
</div>
<table>
<tbody>
<tr v-for="shortcut in shortcuts" :key="shortcut.keys">
<td><kbd>{{ shortcut.keys }}</kbd></td>
<td>{{ shortcut.action }}</td>
</tr>
</tbody>
</table>
</div>
</template>
@@ -84,6 +107,18 @@ export default {
save_timeout: null,
key_locked: false,
key_timeout: null,
show_shortcuts: false,
shortcuts: [
{ keys: '← / →', action: 'Previous / next page' },
{ keys: '↑ / ↓', action: 'Scroll within the page' },
{ keys: 'Space', action: 'Next page' },
{ keys: 'Shift + Space', action: 'Previous page' },
{ keys: 'n / p', action: 'Next / previous page' },
{ keys: 'Home / End', action: 'First / last page' },
{ keys: 'm', action: 'Switch reading mode' },
{ keys: '?', action: 'Show or hide this list' },
{ keys: 'Esc', action: 'Hide this list' },
],
}
},
props: {
@@ -181,6 +216,10 @@ export default {
return
}
if (!this.deck) {
return
}
this.current_page = pageNum-1
this.deck.slide(this.current_page)
},
@@ -197,6 +236,17 @@ export default {
return
}
// These only show or hide the shortcut list, so they still work when a control
// has focus.
if (e.key === 'Escape') {
this.show_shortcuts = false
return
}
if (e.key === '?') {
this.show_shortcuts = !this.show_shortcuts
return
}
// The reader listens on window, so a key pressed while a control has focus would
// otherwise page as well as activate that control.
if (e.target && e.target.closest && e.target.closest('input, select, textarea, button')) {
@@ -213,10 +263,34 @@ export default {
// scrolling: the page is taller than the viewport, and intercepting them here would
// double up with the native scroll. In continuous mode the observer records whichever
// page is topmost, so scrolling inside a page does not change the saved page.
if (e.key === 'ArrowRight') {
this.nextPage('auto')
} else if (e.key === 'ArrowLeft') {
this.prevPage('auto')
const key = e.key.toLowerCase()
switch (key) {
case 'arrowright':
case 'n':
this.nextPage('auto')
return
case 'arrowleft':
case 'p':
this.prevPage('auto')
return
case ' ':
// Space would otherwise scroll the page as well as turning it.
e.preventDefault?.()
if (e.shiftKey) {
this.prevPage('auto')
} else {
this.nextPage('auto')
}
return
case 'home':
case 'end':
// Same for Home/End, which the browser would scroll to the page edges.
e.preventDefault?.()
this.setPage(key === 'home' ? 1 : this.pages)
return
case 'm':
this.setMode(this.mode === 'paged' ? 'scroll' : 'paged')
return
}
},
// Continuous mode: reveal is not used for visibility here, so the page in view is
@@ -415,6 +489,36 @@ section {
padding-bottom: 60px;
}
.shortcuts {
position: fixed;
right: 12px;
bottom: 64px;
max-width: 340px;
padding: 10px 12px;
border: 1px solid #adb5bd;
border-radius: 6px;
background: rgba(255, 255, 255, 0.95);
font-size: 0.85rem;
z-index: 20;
}
.shortcuts-head {
display: flex;
justify-content: space-between;
align-items: center;
margin-bottom: 6px;
}
.shortcuts td {
padding: 2px 8px 2px 0;
vertical-align: top;
}
.shortcuts kbd {
font-family: inherit;
white-space: nowrap;
}
/* reveal.css is deliberately not loaded, so visibility is the `hidden` attribute and
reveal's own transition classes do nothing. A transition cannot run across
display:none -> block, so paged mode uses an animation on the slide that becomes