on master help sign in
Fix goto line number
b90450bGokul Soumya
helix-term/src/commands.rs+20−4
@@ -228,13 +228,14 @@ impl Command {
228 goto_definition, "Goto definition",
228 goto_definition, "Goto definition",
229 goto_type_definition, "Goto type definition",
229 goto_type_definition, "Goto type definition",
230 goto_implementation, "Goto implementation",
230 goto_implementation, "Goto implementation",
231− goto_file_start, "Goto file start",
231+ goto_file_start, "Goto file start/line",
232 goto_file_end, "Goto file end",
232 goto_file_end, "Goto file end",
233 goto_reference, "Goto references",
233 goto_reference, "Goto references",
234 goto_window_top, "Goto window top",
234 goto_window_top, "Goto window top",
235 goto_window_middle, "Goto window middle",
235 goto_window_middle, "Goto window middle",
236 goto_window_bottom, "Goto window bottom",
236 goto_window_bottom, "Goto window bottom",
237 goto_last_accessed_file, "Goto last accessed file",
237 goto_last_accessed_file, "Goto last accessed file",
238+ goto_line, "Goto line",
238 goto_first_diag, "Goto first diagnostic",
239 goto_first_diag, "Goto first diagnostic",
239 goto_last_diag, "Goto last diagnostic",
240 goto_last_diag, "Goto last diagnostic",
240 goto_next_diag, "Goto next diagnostic",
241 goto_next_diag, "Goto next diagnostic",
@@ -566,9 +567,13 @@ fn move_next_long_word_end(cx: &mut Context) {
566}
567}
567
568
568fn goto_file_start(cx: &mut Context) {
569fn goto_file_start(cx: &mut Context) {
570+ if cx.count.is_some() {
571+ goto_line(cx);
572+ } else {
569− push_jump(cx.editor);
573+ push_jump(cx.editor);
570− let (view, doc) = current!(cx.editor);
574+ let (view, doc) = current!(cx.editor);
571− doc.set_selection(view.id, Selection::point(0));
575+ doc.set_selection(view.id, Selection::point(0));
576+ }
572}
577}
573
578
574fn goto_file_end(cx: &mut Context) {
579fn goto_file_end(cx: &mut Context) {
@@ -2387,6 +2392,17 @@ fn push_jump(editor: &mut Editor) {
2387 view.jumps.push(jump);
2392 view.jumps.push(jump);
2388}
2393}
2389
2394
2395+fn goto_line(cx: &mut Context) {
2396+ if let Some(count) = cx.count {
2397+ push_jump(cx.editor);
2398+
2399+ let (view, doc) = current!(cx.editor);
2400+ let line_idx = std::cmp::min(count.get() - 1, doc.text().len_lines().saturating_sub(2));
2401+ let pos = doc.text().line_to_char(line_idx);
2402+ doc.set_selection(view.id, Selection::point(pos));
2403+ }
2404+}
2405+
2390fn goto_last_accessed_file(cx: &mut Context) {
2406fn goto_last_accessed_file(cx: &mut Context) {
2391 let alternate_file = view!(cx.editor).last_accessed_doc;
2407 let alternate_file = view!(cx.editor).last_accessed_doc;
2392 if let Some(alt) = alternate_file {
2408 if let Some(alt) = alternate_file {
helix-term/src/keymap.rs+1
@@ -356,6 +356,7 @@ impl Default for Keymaps {
356 "E" => move_next_long_word_end,
356 "E" => move_next_long_word_end,
357
357
358 "v" => select_mode,
358 "v" => select_mode,
359+ "G" => goto_line,
359 "g" => { "Goto"
360 "g" => { "Goto"
360 "g" => goto_file_start,
361 "g" => goto_file_start,
361 "e" => goto_file_end,
362 "e" => goto_file_end,