From 1fd472f4d85d8dca63b2437c546ff23c1b3ce9d3 Mon Sep 17 00:00:00 2001 From: Casey Rodarmor Date: Mon, 19 Oct 2026 22:59:46 -0700 Subject: [PATCH 1/2] Allow navigating between items with left and right arrow --- src/shortcut.rs | 2 +- src/templates/item.rs | 4 ++-- src/templates/page.rs | 14 +++++++------- static/page.css | 2 ++ static/page.js | 9 +++++++-- templates/page.html | 2 +- 6 files changed, 20 insertions(+), 13 deletions(-) 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..cef0f860 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
+
←p
go to previous
+
→n
go to next
u
go up
f
foo
?
toggle shortcuts
diff --git a/static/page.css b/static/page.css index 59d3bc0f..7e147edc 100644 --- a/static/page.css +++ b/static/page.css @@ -254,6 +254,8 @@ body > header > nav { } dt { + display: flex; font-style: normal; + gap: var(--space-1); } } 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..39123931 100644 --- a/templates/page.html +++ b/templates/page.html @@ -51,7 +51,7 @@
%% for shortcut in self.shortcuts() { -
{{ shortcut.key }}
{{ shortcut.description }}
+
{% for key in shortcut.keys { %}{{ key }}{% } %}
{{ shortcut.description }}
%% }
From 760ba651e92953fbf712ee74ce12e5b55a26ef5c Mon Sep 17 00:00:00 2001 From: Casey Rodarmor Date: Mon, 19 Oct 2026 23:06:09 -0700 Subject: [PATCH 2/2] Reform --- src/templates/page.rs | 4 ++-- static/page.css | 4 +--- templates/page.html | 2 +- 3 files changed, 4 insertions(+), 6 deletions(-) diff --git a/src/templates/page.rs b/src/templates/page.rs index cef0f860..8f37ac82 100644 --- a/src/templates/page.rs +++ b/src/templates/page.rs @@ -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 7e147edc..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; } @@ -254,8 +254,6 @@ body > header > nav { } dt { - display: flex; font-style: normal; - gap: var(--space-1); } } diff --git a/templates/page.html b/templates/page.html index 39123931..9d9b56e7 100644 --- a/templates/page.html +++ b/templates/page.html @@ -51,7 +51,7 @@
%% for shortcut in self.shortcuts() { -
{% for key in shortcut.keys { %}{{ key }}{% } %}
{{ shortcut.description }}
+
{% for (i, key) in shortcut.keys.iter().enumerate() { %}{% if i > 0 { %} or {% } %}{{ key }}{% } %}
{{ shortcut.description }}
%% }