Support ctrl-f and ctrl-b to page up/down, fixes #41

This commit is contained in:
Blaž Hrastnik 2021-06-02 13:19:21 +09:00
parent 0851110d10
commit cbb3ebafdc
2 changed files with 6 additions and 4 deletions

View File

@ -473,10 +473,10 @@ fn scroll(cx: &mut Context, offset: usize, direction: Direction) {
let last_line = view.last_line(doc); let last_line = view.last_line(doc);
// clamp into viewport // clamp into viewport
let line = cursor.row.clamp( let line = cursor
view.first_line + scrolloff, .row
last_line.saturating_sub(scrolloff), .min(view.first_line + scrolloff)
); .max(last_line.saturating_sub(scrolloff));
let text = doc.text().slice(..); let text = doc.text().slice(..);
let pos = pos_at_coords(text, Position::new(line, cursor.col)); // this func will properly truncate to line end let pos = pos_at_coords(text, Position::new(line, cursor.col)); // this func will properly truncate to line end

View File

@ -240,10 +240,12 @@ pub fn default() -> Keymaps {
code: KeyCode::PageUp, code: KeyCode::PageUp,
modifiers: KeyModifiers::NONE modifiers: KeyModifiers::NONE
} => commands::page_up, } => commands::page_up,
ctrl!('b') => commands::page_up,
KeyEvent { KeyEvent {
code: KeyCode::PageDown, code: KeyCode::PageDown,
modifiers: KeyModifiers::NONE modifiers: KeyModifiers::NONE
} => commands::page_down, } => commands::page_down,
ctrl!('f') => commands::page_down,
ctrl!('u') => commands::half_page_up, ctrl!('u') => commands::half_page_up,
ctrl!('d') => commands::half_page_down, ctrl!('d') => commands::half_page_down,