From 436c5ed22f779c0c2649271566e4216d26d81d46 Mon Sep 17 00:00:00 2001 From: Mitsutoshi Aoe Date: Thu, 6 Jun 2024 16:36:35 +0900 Subject: [PATCH 1/2] Accept space key to page down --- src/prompt.rs | 1 + 1 file changed, 1 insertion(+) diff --git a/src/prompt.rs b/src/prompt.rs index 38b0567..4ffb2ec 100644 --- a/src/prompt.rs +++ b/src/prompt.rs @@ -78,6 +78,7 @@ impl Prompt { KeyCode::Home => Some(Cmd::RowTop), KeyCode::PageUp => Some(Cmd::RowPgUp), KeyCode::PageDown => Some(Cmd::RowPgDown), + KeyCode::PageDown | KeyCode::Char(' ') => Some(Cmd::RowPgDown), KeyCode::Esc | KeyCode::Char('q') => Some(Cmd::Exit), KeyCode::Char('/') => { self.input.clear(); From 23da2196adaf1a50a37b3a387e06c213970ee03c Mon Sep 17 00:00:00 2001 From: Mitsutoshi Aoe Date: Thu, 6 Jun 2024 16:37:17 +0900 Subject: [PATCH 2/2] Accept ctrl-b to page up --- src/main.rs | 2 +- src/prompt.rs | 8 +++++--- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/src/main.rs b/src/main.rs index 21261a3..56311fa 100644 --- a/src/main.rs +++ b/src/main.rs @@ -299,7 +299,7 @@ fn runloop( { return Ok(()) } - code => prompt.handle_key(code), + code => prompt.handle_key(code, k.modifiers), }, event::Event::Mouse(ev) => prompt.handle_mouse(ev), event::Event::Resize(cols, rows) => { diff --git a/src/prompt.rs b/src/prompt.rs index 4ffb2ec..22dcdc5 100644 --- a/src/prompt.rs +++ b/src/prompt.rs @@ -1,4 +1,4 @@ -use crossterm::event::{KeyCode, MouseButton, MouseEvent, MouseEventKind}; +use crossterm::event::{KeyCode, KeyModifiers, MouseButton, MouseEvent, MouseEventKind}; use std::io::Write; #[derive(Default)] @@ -63,7 +63,7 @@ impl Prompt { matches!(self.mode, Mode::Follow) } - pub fn handle_key(&mut self, key: KeyCode) -> Option { + pub fn handle_key(&mut self, key: KeyCode, modifiers: KeyModifiers) -> Option { match self.mode { Mode::Normal => match key { KeyCode::Right | KeyCode::Char('l') => Some(Cmd::ColRight), @@ -77,7 +77,9 @@ impl Prompt { } KeyCode::Home => Some(Cmd::RowTop), KeyCode::PageUp => Some(Cmd::RowPgUp), - KeyCode::PageDown => Some(Cmd::RowPgDown), + KeyCode::Char('b') if modifiers.contains(KeyModifiers::CONTROL) => { + Some(Cmd::RowPgUp) + } KeyCode::PageDown | KeyCode::Char(' ') => Some(Cmd::RowPgDown), KeyCode::Esc | KeyCode::Char('q') => Some(Cmd::Exit), KeyCode::Char('/') => {