on master help sign in
started work on page up/down
commit1035b2aea170b68c7f0ed62fa0414e0ed48d5792 authorJan Hrastnik <jan.hrastnik2@gmail.com> dateMon 5 Oct 2020, 17:18 (6 years ago) parent7ccc499
2 files changed+28−1
helix-view/src/commands.rs+18−1 helix-view/src/keymap.rs+10
helix-view/src/commands.rs+18−1
@@ -127,12 +127,29 @@ pub fn move_file_start(view: &mut View, _count: usize) {
127127pub fn move_file_end(view: &mut View, _count: usize) {
128128 // TODO: use a transaction
129129 let text = &view.state.doc;
130− let last_line = text.line_to_char(text.len_lines().checked_sub(1).unwrap());
130+ let last_line = text.line_to_char(text.len_lines().checked_sub(2).unwrap());
131131 view.state.selection = Selection::single(last_line, last_line);
132132
133133 view.state.mode = Mode::Normal;
134134}
135135
136+pub fn page_up(view: &mut View, _count: usize) {
137+ view.first_line = view.first_line.saturating_sub(view.size.1);
138+ view.state.selection = Selection::single(view.first_line as usize, view.first_line as usize);
139+}
140+
141+pub fn page_down(view: &mut View, _count: usize) {
142+ view.first_line += view.size.1;
143+ view.state.selection = Selection::single(view.first_line as usize, view.first_line as usize);
144+}
145+
146+pub fn half_page_up(view: &mut View, _count: usize) {
147+ view.first_line = view.first_line.saturating_sub(view.size.1 / 2);
148+}
149+
150+pub fn half_page_down(view: &mut View, _count: usize) {
151+ view.first_line += view.size.1 / 2;
152+}
136153// avoid select by default by having a visual mode switch that makes movements into selects
137154
138155pub fn extend_char_left(view: &mut View, count: usize) {
helix-view/src/keymap.rs+10
@@ -140,6 +140,16 @@ pub fn default() -> Keymaps {
140140 code: KeyCode::Esc,
141141 modifiers: Modifiers::NONE
142142 }] => commands::normal_mode,
143+ vec![Key {
144+ code: KeyCode::PageUp,
145+ modifiers: Modifiers::NONE
146+ }] => commands::page_up,
147+ vec![Key {
148+ code: KeyCode::PageDown,
149+ modifiers: Modifiers::NONE
150+ }] => commands::page_down,
151+ vec![shift!('u')] => commands::half_page_up,
152+ vec![shift!('d')] => commands::half_page_down,
143153 ),
144154 state::Mode::Insert => hashmap!(
145155 vec![Key {