on master help sign in
started work on page up/down
1035b2aJan Hrastnik
helix-view/src/commands.rs+18−1
@@ -127,12 +127,29 @@ pub fn move_file_start(view: &mut View, _count: usize) {
127pub fn move_file_end(view: &mut View, _count: usize) {
127pub fn move_file_end(view: &mut View, _count: usize) {
128 // TODO: use a transaction
128 // TODO: use a transaction
129 let text = &view.state.doc;
129 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());
131 view.state.selection = Selection::single(last_line, last_line);
131 view.state.selection = Selection::single(last_line, last_line);
132
132
133 view.state.mode = Mode::Normal;
133 view.state.mode = Mode::Normal;
134}
134}
135
135
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+}
136// avoid select by default by having a visual mode switch that makes movements into selects
153// avoid select by default by having a visual mode switch that makes movements into selects
137
154
138pub fn extend_char_left(view: &mut View, count: usize) {
155pub fn extend_char_left(view: &mut View, count: usize) {
helix-view/src/keymap.rs+10
@@ -140,6 +140,16 @@ pub fn default() -> Keymaps {
140 code: KeyCode::Esc,
140 code: KeyCode::Esc,
141 modifiers: Modifiers::NONE
141 modifiers: Modifiers::NONE
142 }] => commands::normal_mode,
142 }] => 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,
143 ),
153 ),
144 state::Mode::Insert => hashmap!(
154 state::Mode::Insert => hashmap!(
145 vec![Key {
155 vec![Key {