diff --git a/README.md b/README.md index 7b79fb3..effb5ad 100644 --- a/README.md +++ b/README.md @@ -27,7 +27,12 @@ App for reading [Hacker News](https://news.ycombinator.com/). - `F5` - Refresh - `Backspace` - Go back to story view from comment section - `Alt + Left Arrow` - Go back a page -- `Alt + Right Arrow` - Got to next page (load more) +- `Alt + Right Arrow` - Go to next page (load more) +- `Alt + 1` - Switch to Top tab +- `Alt + 2` - Switch to New tab +- `Alt + 3` - Switch to Show HN tab +- `Alt + 4` - Switch to Ask HN tab +- `Alt + 5` - Switch to Jobs tab - `F12` - Debug menu ### Accessibility keyboard shortcuts diff --git a/src/main.rs b/src/main.rs index 98c1b35..2a80866 100644 --- a/src/main.rs +++ b/src/main.rs @@ -26,6 +26,11 @@ pub const GO_BACK_FROM_COMMENTS: KeyboardShortcut = KeyboardShortcut::new(Modifiers::NONE, Key::Backspace); pub const GO_BACK: KeyboardShortcut = KeyboardShortcut::new(Modifiers::ALT, Key::ArrowLeft); pub const GO_NEXT: KeyboardShortcut = KeyboardShortcut::new(Modifiers::ALT, Key::ArrowRight); +pub const TAB_TOP: KeyboardShortcut = KeyboardShortcut::new(Modifiers::ALT, Key::Num1); +pub const TAB_NEW: KeyboardShortcut = KeyboardShortcut::new(Modifiers::ALT, Key::Num2); +pub const TAB_SHOW: KeyboardShortcut = KeyboardShortcut::new(Modifiers::ALT, Key::Num3); +pub const TAB_ASK: KeyboardShortcut = KeyboardShortcut::new(Modifiers::ALT, Key::Num4); +pub const TAB_JOBS: KeyboardShortcut = KeyboardShortcut::new(Modifiers::ALT, Key::Num5); #[derive(Deserialize, Clone, Copy, PartialEq, Eq, Hash, Default)] struct HnItemId(usize); @@ -409,6 +414,26 @@ impl eframe::App for Application { let old_page = self.page_name; + if ctx.input_mut(|i| i.consume_shortcut(&TAB_TOP)) { + self.page_name = Page::Top; + } + + if ctx.input_mut(|i| i.consume_shortcut(&TAB_NEW)) { + self.page_name = Page::New; + } + + if ctx.input_mut(|i| i.consume_shortcut(&TAB_SHOW)) { + self.page_name = Page::Show; + } + + if ctx.input_mut(|i| i.consume_shortcut(&TAB_ASK)) { + self.page_name = Page::Ask; + } + + if ctx.input_mut(|i| i.consume_shortcut(&TAB_JOBS)) { + self.page_name = Page::Jobs; + } + egui::TopBottomPanel::top("header").show(ctx, |ui| { ui.horizontal(|ui| { self.y_icon.as_ref().unwrap().show(ui);