diff options
author | Jan Hrastnik | 2020-10-05 15:18:29 +0000 |
---|---|---|
committer | Jan Hrastnik | 2020-10-05 15:18:29 +0000 |
commit | 1035b2aea170b68c7f0ed62fa0414e0ed48d5792 (patch) | |
tree | 05362b0875a3a00597af3b1b640e913043669e55 /helix-view | |
parent | 7ccc4993f4814f72106de4882d00614fdc67ba13 (diff) |
started work on page up/down
Diffstat (limited to 'helix-view')
-rw-r--r-- | helix-view/src/commands.rs | 19 | ||||
-rw-r--r-- | helix-view/src/keymap.rs | 10 |
2 files changed, 28 insertions, 1 deletions
diff --git a/helix-view/src/commands.rs b/helix-view/src/commands.rs index 43c27cb4..1d8d851e 100644 --- a/helix-view/src/commands.rs +++ b/helix-view/src/commands.rs @@ -127,12 +127,29 @@ pub fn move_file_start(view: &mut View, _count: usize) { pub fn move_file_end(view: &mut View, _count: usize) { // TODO: use a transaction let text = &view.state.doc; - let last_line = text.line_to_char(text.len_lines().checked_sub(1).unwrap()); + let last_line = text.line_to_char(text.len_lines().checked_sub(2).unwrap()); view.state.selection = Selection::single(last_line, last_line); view.state.mode = Mode::Normal; } +pub fn page_up(view: &mut View, _count: usize) { + view.first_line = view.first_line.saturating_sub(view.size.1); + view.state.selection = Selection::single(view.first_line as usize, view.first_line as usize); +} + +pub fn page_down(view: &mut View, _count: usize) { + view.first_line += view.size.1; + view.state.selection = Selection::single(view.first_line as usize, view.first_line as usize); +} + +pub fn half_page_up(view: &mut View, _count: usize) { + view.first_line = view.first_line.saturating_sub(view.size.1 / 2); +} + +pub fn half_page_down(view: &mut View, _count: usize) { + view.first_line += view.size.1 / 2; +} // avoid select by default by having a visual mode switch that makes movements into selects pub fn extend_char_left(view: &mut View, count: usize) { diff --git a/helix-view/src/keymap.rs b/helix-view/src/keymap.rs index c93c3c1f..27176423 100644 --- a/helix-view/src/keymap.rs +++ b/helix-view/src/keymap.rs @@ -140,6 +140,16 @@ pub fn default() -> Keymaps { code: KeyCode::Esc, modifiers: Modifiers::NONE }] => commands::normal_mode, + vec![Key { + code: KeyCode::PageUp, + modifiers: Modifiers::NONE + }] => commands::page_up, + vec![Key { + code: KeyCode::PageDown, + modifiers: Modifiers::NONE + }] => commands::page_down, + vec![shift!('u')] => commands::half_page_up, + vec![shift!('d')] => commands::half_page_down, ), state::Mode::Insert => hashmap!( vec![Key { |