diff options
author | Blaž Hrastnik | 2021-06-04 06:47:29 +0000 |
---|---|---|
committer | Blaž Hrastnik | 2021-06-04 06:47:29 +0000 |
commit | 4f0e3aa948a83c0d94f942448bfa7740532e55b7 (patch) | |
tree | f71d719e5fa4995feb92c79cdab9fd71d6b4ee1b | |
parent | f2e554d761a8e5f2f7b3cbc5590ff6e5699b13d9 (diff) |
Implement gt/gm/gb, remap goto tYpe to gy
-rw-r--r-- | book/src/keymap.md | 5 | ||||
-rw-r--r-- | helix-term/src/commands.rs | 25 |
2 files changed, 28 insertions, 2 deletions
diff --git a/book/src/keymap.md b/book/src/keymap.md index 8f13ccdb..82cd9f33 100644 --- a/book/src/keymap.md +++ b/book/src/keymap.md @@ -118,8 +118,11 @@ Jumps to various locations. |-----|-----------| | g | Go to the start of the file | | e | Go to the end of the file | +| t | Go to the top of the screen | +| m | Go to the middle of the screen | +| b | Go to the bottom of the screen | | d | Go to definition | -| t | Go to type definition | +| y | Go to type definition | | r | Go to references | | i | Go to implementation | diff --git a/helix-term/src/commands.rs b/helix-term/src/commands.rs index 294c6a0b..c5493cd2 100644 --- a/helix-term/src/commands.rs +++ b/helix-term/src/commands.rs @@ -1270,9 +1270,32 @@ pub fn goto_mode(cx: &mut Context) { 'g' => move_file_start(cx), 'e' => move_file_end(cx), 'd' => goto_definition(cx), - 't' => goto_type_definition(cx), + 'y' => goto_type_definition(cx), 'r' => goto_reference(cx), 'i' => goto_implementation(cx), + + 't' | 'm' | 'b' => { + let (view, doc) = cx.current(); + + let pos = doc.selection(view.id).cursor(); + let line = doc.text().char_to_line(pos); + + let scrolloff = PADDING.min(view.area.height as usize / 2); // TODO: user pref + + let last_line = view.last_line(doc); + + let line = match ch { + 't' => (view.first_line + scrolloff), + 'm' => (view.first_line + (view.area.height as usize / 2)), + 'b' => last_line.saturating_sub(scrolloff), + _ => unreachable!(), + } + .min(last_line.saturating_sub(scrolloff)); + + let pos = doc.text().line_to_char(line); + + doc.set_selection(view.id, Selection::point(pos)); + } _ => (), } } |