Skip to content

Commit

Permalink
input: Add keybindings for horizontal scroll
Browse files Browse the repository at this point in the history
* Add `h` and `Left` for scrolling to left
* Add `l` and `Right` for scrolling to right

Introduce UpdateLeftMark UnerInput event to be fired when the above keys
are pressed
  • Loading branch information
AMythicDev committed Dec 30, 2023
1 parent bc2861f commit f37f1a6
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 0 deletions.
1 change: 1 addition & 0 deletions src/core/ev_handler.rs
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ pub fn handle_event(
display::draw_for_change(out, p, &mut um)?;
p.upper_mark = um;
}
Command::UserInput(InputEvent::UpdateLeftMark(lm)) => p.left_mark = lm,
Command::UserInput(InputEvent::RestorePrompt) => {
// Set the message to None and new messages to false as all messages have been shown
p.message = None;
Expand Down
23 changes: 23 additions & 0 deletions src/input/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,8 @@ pub enum InputEvent {
UpdateUpperMark(usize),
/// `Ctrl+L`, inverts the line number display. Contains the new value.
UpdateLineNumber(LineNumbers),
/// `Right`, `Left`, `h` or `l` was pressed
UpdateLeftMark(usize),
/// A number key has been pressed. This inner value is stored as a `char`.
/// The input loop will append this number to its `count` string variable
Number(char),
Expand Down Expand Up @@ -440,6 +442,7 @@ impl InputClassifier for DefaultInputClassifier {
modifiers: KeyModifiers::CONTROL,
..
}) => Some(InputEvent::UpdateLineNumber(!ps.line_numbers)),

// Quit.
Event::Key(KeyEvent {
code: KeyCode::Char('q'),
Expand All @@ -451,6 +454,26 @@ impl InputClassifier for DefaultInputClassifier {
modifiers: KeyModifiers::CONTROL,
..
}) => Some(InputEvent::Exit),

// Horizontal scrolling
Event::Key(KeyEvent {
code: KeyCode::Char('h'),
modifiers: KeyModifiers::NONE,
})
| Event::Key(KeyEvent {
code: KeyCode::Left,
modifiers: KeyModifiers::NONE,
}) => Some(InputEvent::UpdateLeftMark(ps.left_mark.saturating_sub(1))),
Event::Key(KeyEvent {
code: KeyCode::Char('l'),
modifiers: KeyModifiers::NONE,
})
| Event::Key(KeyEvent {
code: KeyCode::Right,
modifiers: KeyModifiers::NONE,
}) => Some(InputEvent::UpdateLeftMark(ps.left_mark.saturating_add(1))),

// Search
#[cfg(feature = "search")]
Event::Key(KeyEvent {
code: KeyCode::Char('/'),
Expand Down

0 comments on commit f37f1a6

Please sign in to comment.