Skip to content

Commit

Permalink
pgup/down
Browse files Browse the repository at this point in the history
  • Loading branch information
achristmascarl committed Sep 18, 2024
1 parent 9831e67 commit c930aad
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 17 deletions.
18 changes: 12 additions & 6 deletions src/components/scroll_table.rs
Original file line number Diff line number Diff line change
Expand Up @@ -115,16 +115,22 @@ impl<'a> ScrollTable<'a> {
}

pub fn pg_up(&mut self) -> &mut Self {
self.y_offset = self
.y_offset
.saturating_sub(self.pg_height.saturating_div(2).saturating_sub(u16::from(self.pg_height % 2 == 0)) as usize); // always round down
self.y_offset = self.y_offset.saturating_sub(std::cmp::max(
1,
self.pg_height.saturating_div(2).saturating_sub(
u16::from(self.pg_height % 2 == 0), // always round down
) as usize,
));
self
}

pub fn pg_down(&mut self) -> &mut Self {
let new_y_offset = self
.y_offset
.saturating_add(self.pg_height.saturating_div(2).saturating_sub(u16::from(self.pg_height % 2 == 0)) as usize); // always round down
let new_y_offset = self.y_offset.saturating_add(std::cmp::max(
1,
self.pg_height.saturating_div(2).saturating_sub(
u16::from(self.pg_height % 2 == 0), // always rounds down
) as usize,
));
self.y_offset = std::cmp::min(self.max_y_offset, new_y_offset);
self
}
Expand Down
24 changes: 13 additions & 11 deletions src/vim.rs
Original file line number Diff line number Diff line change
Expand Up @@ -233,8 +233,12 @@ impl Vim {
Input { key: Key::Char('y'), ctrl: true, .. } => textarea.scroll((-1, 0)),
Input { key: Key::Char('d'), ctrl: true, .. } => textarea.scroll(Scrolling::HalfPageDown),
Input { key: Key::Char('u'), ctrl: true, .. } => textarea.scroll(Scrolling::HalfPageUp),
Input { key: Key::Char('f'), ctrl: true, .. } => textarea.scroll(Scrolling::PageDown),
Input { key: Key::Char('b'), ctrl: true, .. } => textarea.scroll(Scrolling::PageUp),
Input { key: Key::Char('f'), ctrl: true, .. } | Input { key: Key::PageDown, .. } => {
textarea.scroll(Scrolling::PageDown)
},
Input { key: Key::Char('b'), ctrl: true, .. } | Input { key: Key::PageUp, .. } => {
textarea.scroll(Scrolling::PageUp)
},
Input { key: Key::Char('v'), ctrl: false, .. } if self.mode == Mode::Normal => {
textarea.start_selection();
return Transition::Mode(Mode::Visual);
Expand Down Expand Up @@ -401,15 +405,13 @@ impl Vim {
},
}
},
Mode::Replace => {
match input {
Input { key: Key::Esc, .. } | Input { key: Key::Char('c'), ctrl: true, .. } => Transition::Mode(Mode::Normal),
input => {
textarea.delete_str(1);
textarea.input(input);
Transition::Mode(Mode::Normal)
},
}
Mode::Replace => match input {
Input { key: Key::Esc, .. } | Input { key: Key::Char('c'), ctrl: true, .. } => Transition::Mode(Mode::Normal),
input => {
textarea.delete_str(1);
textarea.input(input);
Transition::Mode(Mode::Normal)
},
},
}
}
Expand Down

0 comments on commit c930aad

Please sign in to comment.