diff --git a/src/shortcut.rs b/src/shortcut.rs index 00ff342b..7accd74b 100644 --- a/src/shortcut.rs +++ b/src/shortcut.rs @@ -3,5 +3,5 @@ use super::*; #[derive(Debug, PartialEq)] pub struct Shortcut { pub(crate) description: &'static str, - pub(crate) key: char, + pub(crate) keys: &'static [char], } diff --git a/src/templates/item.rs b/src/templates/item.rs index f9347364..b404fd25 100644 --- a/src/templates/item.rs +++ b/src/templates/item.rs @@ -74,7 +74,7 @@ impl Page for ItemHtml { fn shortcuts(&self) -> Vec { vec![Shortcut { description: "toggle full screen", - key: 'f', + keys: &['f'], }] } @@ -531,7 +531,7 @@ mod tests { ItemHtml::default().shortcuts(), vec![Shortcut { description: "toggle full screen", - key: 'f', + keys: &['f'], }], ); } diff --git a/src/templates/page.rs b/src/templates/page.rs index 623a948f..8f37ac82 100644 --- a/src/templates/page.rs +++ b/src/templates/page.rs @@ -13,21 +13,21 @@ impl PageHtml { if self.content.prev().is_some() { shortcuts.push(Shortcut { description: "go to previous", - key: 'p', + keys: &['←', 'p'], }); } if self.content.next().is_some() { shortcuts.push(Shortcut { description: "go to next", - key: 'n', + keys: &['→', 'n'], }); } if self.content.up().is_some() { shortcuts.push(Shortcut { description: "go up", - key: 'u', + keys: &['u'], }); } @@ -35,7 +35,7 @@ impl PageHtml { shortcuts.push(Shortcut { description: "toggle shortcuts", - key: '?', + keys: &['?'], }); shortcuts @@ -100,7 +100,7 @@ mod tests { fn shortcuts(&self) -> Vec { vec![Shortcut { description: "foo", - key: 'f', + keys: &['f'], }] } @@ -167,8 +167,8 @@ mod tests {
-
p
go to previous
-
n
go to next
+
← or p
go to previous
+
→ or n
go to next
u
go up
f
foo
?
toggle shortcuts
diff --git a/static/page.css b/static/page.css index 59d3bc0f..755af958 100644 --- a/static/page.css +++ b/static/page.css @@ -48,7 +48,7 @@ body { min-height: 100dvh; } -code { +code, kbd { font-family: ui-monospace, Menlo, "Cascadia Mono", Consolas, "DejaVu Sans Mono", monospace; } diff --git a/static/page.js b/static/page.js index 2b0edecc..2614b7bc 100644 --- a/static/page.js +++ b/static/page.js @@ -17,8 +17,13 @@ document.addEventListener('keydown', (event) => { return; } - let link = event.key === 'p' ? prev - : event.key === 'n' ? next + let arrow = event.key === 'ArrowLeft' || event.key === 'ArrowRight'; + if (arrow && event.target.matches('audio, video, input, textarea, select')) { + return; + } + + let link = event.key === 'ArrowLeft' || event.key === 'p' ? prev + : event.key === 'ArrowRight' || event.key === 'n' ? next : event.key === 'u' ? up : null; diff --git a/templates/page.html b/templates/page.html index fcec1411..9d9b56e7 100644 --- a/templates/page.html +++ b/templates/page.html @@ -51,7 +51,7 @@
%% for shortcut in self.shortcuts() { -
{{ shortcut.key }}
{{ shortcut.description }}
+
{% for (i, key) in shortcut.keys.iter().enumerate() { %}{% if i > 0 { %} or {% } %}{{ key }}{% } %}
{{ shortcut.description }}
%% }