Skip to content

Commit

Permalink
Add page tab shortcuts
Browse files Browse the repository at this point in the history
  • Loading branch information
richardhozak committed Feb 19, 2023
1 parent a78fb0c commit 4b7f97f
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 1 deletion.
7 changes: 6 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
25 changes: 25 additions & 0 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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);
Expand Down

0 comments on commit 4b7f97f

Please sign in to comment.