on master help sign in
Implement gt/gm/gb, remap goto tYpe to gy
commit4f0e3aa948a83c0d94f942448bfa7740532e55b7 authorBlaž Hrastnik <blaz@mxxn.io> dateFri 4 Jun 2021, 15:47 (5 years ago) parentf2e554d
2 files changed+28−2
book/src/keymap.md+4−1 helix-term/src/commands.rs+24−1
book/src/keymap.md+4−1
@@ -118,8 +118,11 @@ Jumps to various locations.
118118|-----|-----------|
119119| g | Go to the start of the file |
120120| e | Go to the end of the file |
121+| t | Go to the top of the screen |
122+| m | Go to the middle of the screen |
123+| b | Go to the bottom of the screen |
121124| d | Go to definition |
122−| t | Go to type definition |
125+| y | Go to type definition |
123126| r | Go to references |
124127| i | Go to implementation |
125128
helix-term/src/commands.rs+24−1
@@ -1270,9 +1270,32 @@ pub fn goto_mode(cx: &mut Context) {
12701270 'g' => move_file_start(cx),
12711271 'e' => move_file_end(cx),
12721272 'd' => goto_definition(cx),
1273− 't' => goto_type_definition(cx),
1273+ 'y' => goto_type_definition(cx),
12741274 'r' => goto_reference(cx),
12751275 'i' => goto_implementation(cx),
1276+
1277+ 't' | 'm' | 'b' => {
1278+ let (view, doc) = cx.current();
1279+
1280+ let pos = doc.selection(view.id).cursor();
1281+ let line = doc.text().char_to_line(pos);
1282+
1283+ let scrolloff = PADDING.min(view.area.height as usize / 2); // TODO: user pref
1284+
1285+ let last_line = view.last_line(doc);
1286+
1287+ let line = match ch {
1288+ 't' => (view.first_line + scrolloff),
1289+ 'm' => (view.first_line + (view.area.height as usize / 2)),
1290+ 'b' => last_line.saturating_sub(scrolloff),
1291+ _ => unreachable!(),
1292+ }
1293+ .min(last_line.saturating_sub(scrolloff));
1294+
1295+ let pos = doc.text().line_to_char(line);
1296+
1297+ doc.set_selection(view.id, Selection::point(pos));
1298+ }
12761299 _ => (),
12771300 }
12781301 }