Fix home/end

pull/6/head
dvkt 4 years ago
parent 95934b3900
commit ee7f5ef670

@ -554,6 +554,14 @@ impl Menu {
}
Key::PageUp | Key::Ctrl('-') | Key::Char('-') => self.action_page_up(),
Key::PageDown | Key::Ctrl(' ') | Key::Char(' ') => self.action_page_down(),
Key::Home => {
self.scroll = 0;
Action::Redraw
}
Key::End => {
self.scroll = self.final_scroll();
Action::Redraw
}
Key::Char('f') | Key::Ctrl('f') | Key::Char('/') | Key::Char('i') | Key::Ctrl('i') => {
self.searching = true;
Action::Redraw

@ -37,19 +37,15 @@ impl View for Text {
Action::Redraw
}
Key::End => {
if self.lines >= SCROLL_LINES {
self.scroll = self.lines - SCROLL_LINES;
Action::Redraw
} else {
Action::None
}
self.scroll = self.final_scroll();
Action::Redraw
}
Key::Char('w') | Key::Ctrl('w') => {
self.wide = !self.wide;
Action::Redraw
}
Key::Down | Key::Ctrl('n') | Key::Char('n') | Key::Ctrl('j') | Key::Char('j') => {
if self.scroll < self.padding() {
if self.scroll < self.final_scroll() {
self.scroll += 1;
Action::Redraw
} else {
@ -77,16 +73,11 @@ impl View for Text {
}
}
Key::PageDown | Key::Char(' ') => {
let padding = self.padding();
if self.scroll < padding {
self.scroll += SCROLL_LINES;
if self.scroll >= padding {
self.scroll = padding;
}
Action::Redraw
} else {
Action::None
self.scroll += SCROLL_LINES;
if self.scroll > self.final_scroll() {
self.scroll = self.final_scroll();
}
Action::Redraw
}
_ => Action::Keypress(c),
}
@ -150,8 +141,8 @@ impl Text {
}
}
// how many rows to pad with blank lines at the end of the page
fn padding(&self) -> usize {
/// Final `self.scroll` value.
fn final_scroll(&self) -> usize {
let padding = (self.size.1 as f64 * 0.9) as usize;
if self.lines > padding {
self.lines - padding

Loading…
Cancel
Save