Fix goto line number

Regression from #454. Go to line 10 with `10gg` or `10G`.
This commit is contained in:
Gokul Soumya 2021-07-28 13:25:34 +05:30 committed by Ivan Tham
parent 013bec407c
commit b90450b9e8
2 changed files with 21 additions and 4 deletions

View file

@ -228,13 +228,14 @@ impl Command {
goto_definition, "Goto definition", goto_definition, "Goto definition",
goto_type_definition, "Goto type definition", goto_type_definition, "Goto type definition",
goto_implementation, "Goto implementation", goto_implementation, "Goto implementation",
goto_file_start, "Goto file start", goto_file_start, "Goto file start/line",
goto_file_end, "Goto file end", goto_file_end, "Goto file end",
goto_reference, "Goto references", goto_reference, "Goto references",
goto_window_top, "Goto window top", goto_window_top, "Goto window top",
goto_window_middle, "Goto window middle", goto_window_middle, "Goto window middle",
goto_window_bottom, "Goto window bottom", goto_window_bottom, "Goto window bottom",
goto_last_accessed_file, "Goto last accessed file", goto_last_accessed_file, "Goto last accessed file",
goto_line, "Goto line",
goto_first_diag, "Goto first diagnostic", goto_first_diag, "Goto first diagnostic",
goto_last_diag, "Goto last diagnostic", goto_last_diag, "Goto last diagnostic",
goto_next_diag, "Goto next diagnostic", goto_next_diag, "Goto next diagnostic",
@ -566,9 +567,13 @@ fn move_next_long_word_end(cx: &mut Context) {
} }
fn goto_file_start(cx: &mut Context) { fn goto_file_start(cx: &mut Context) {
push_jump(cx.editor); if cx.count.is_some() {
let (view, doc) = current!(cx.editor); goto_line(cx);
doc.set_selection(view.id, Selection::point(0)); } else {
push_jump(cx.editor);
let (view, doc) = current!(cx.editor);
doc.set_selection(view.id, Selection::point(0));
}
} }
fn goto_file_end(cx: &mut Context) { fn goto_file_end(cx: &mut Context) {
@ -2387,6 +2392,17 @@ fn push_jump(editor: &mut Editor) {
view.jumps.push(jump); view.jumps.push(jump);
} }
fn goto_line(cx: &mut Context) {
if let Some(count) = cx.count {
push_jump(cx.editor);
let (view, doc) = current!(cx.editor);
let line_idx = std::cmp::min(count.get() - 1, doc.text().len_lines().saturating_sub(2));
let pos = doc.text().line_to_char(line_idx);
doc.set_selection(view.id, Selection::point(pos));
}
}
fn goto_last_accessed_file(cx: &mut Context) { fn goto_last_accessed_file(cx: &mut Context) {
let alternate_file = view!(cx.editor).last_accessed_doc; let alternate_file = view!(cx.editor).last_accessed_doc;
if let Some(alt) = alternate_file { if let Some(alt) = alternate_file {

View file

@ -356,6 +356,7 @@ impl Default for Keymaps {
"E" => move_next_long_word_end, "E" => move_next_long_word_end,
"v" => select_mode, "v" => select_mode,
"G" => goto_line,
"g" => { "Goto" "g" => { "Goto"
"g" => goto_file_start, "g" => goto_file_start,
"e" => goto_file_end, "e" => goto_file_end,