on master help sign in
Add `goto_last_line` command, and bind it to `ge`.

Resolves #529.

commit8c3a5b14de37aa3bd9c5c9a0aa2645245d03b161 authorNathan Vegdahl <cessen@cessen.com> dateTue 3 Aug 2021, 06:49 (5 years ago) parent585793e
2 files changed+24−3
helix-term/src/commands.rs+22−1 helix-term/src/keymap.rs+2−2
helix-term/src/commands.rs+22−1
@@ -237,6 +237,7 @@ impl Command {
237237 goto_window_bottom, "Goto window bottom",
238238 goto_last_accessed_file, "Goto last accessed file",
239239 goto_line, "Goto line",
240+ goto_last_line, "Goto last line",
240241 goto_first_diag, "Goto first diagnostic",
241242 goto_last_diag, "Goto last diagnostic",
242243 goto_next_diag, "Goto next diagnostic",
@@ -2426,12 +2427,32 @@ fn goto_line(cx: &mut Context) {
24262427 push_jump(cx.editor);
24272428
24282429 let (view, doc) = current!(cx.editor);
2429− let line_idx = std::cmp::min(count.get() - 1, doc.text().len_lines().saturating_sub(2));
2430+ let max_line = if doc.text().line(doc.text().len_lines() - 1).len_chars() == 0 {
2431+ // If the last line is blank, don't jump to it.
2432+ doc.text().len_lines().saturating_sub(2)
2433+ } else {
2434+ doc.text().len_lines() - 1
2435+ };
2436+ let line_idx = std::cmp::min(count.get() - 1, max_line);
24302437 let pos = doc.text().line_to_char(line_idx);
24312438 doc.set_selection(view.id, Selection::point(pos));
24322439 }
24332440}
24342441
2442+fn goto_last_line(cx: &mut Context) {
2443+ push_jump(cx.editor);
2444+
2445+ let (view, doc) = current!(cx.editor);
2446+ let line_idx = if doc.text().line(doc.text().len_lines() - 1).len_chars() == 0 {
2447+ // If the last line is blank, don't jump to it.
2448+ doc.text().len_lines().saturating_sub(2)
2449+ } else {
2450+ doc.text().len_lines() - 1
2451+ };
2452+ let pos = doc.text().line_to_char(line_idx);
2453+ doc.set_selection(view.id, Selection::point(pos));
2454+}
2455+
24352456fn goto_last_accessed_file(cx: &mut Context) {
24362457 let alternate_file = view!(cx.editor).last_accessed_doc;
24372458 if let Some(alt) = alternate_file {
helix-term/src/keymap.rs+2−2
@@ -359,7 +359,7 @@ impl Default for Keymaps {
359359 "G" => goto_line,
360360 "g" => { "Goto"
361361 "g" => goto_file_start,
362− "e" => goto_file_end,
362+ "e" => goto_last_line,
363363 "h" => goto_line_start,
364364 "l" => goto_line_end,
365365 "s" => goto_first_nonwhitespace,
@@ -617,7 +617,7 @@ fn merge_partial_keys() {
617617 // Assumes that `ge` is in default keymap
618618 assert_eq!(
619619 keymap.root().search(&[key!('g'), key!('e')]).unwrap(),
620− &KeyTrie::Leaf(Command::goto_file_end),
620+ &KeyTrie::Leaf(Command::goto_last_line),
621621 "Old leaves in subnode should be present in merged node"
622622 );
623623