on master help sign in
Limit goto count

Giving a goto count greater than the number of lines in the buffer would cause Helix to panic.

commitfdb5bfafaec05f64f2e759717aade5131496557b authorKevin Sjöberg <mail@kevinsjoberg.com> dateThu 3 Jun 2021, 16:43 (5 years ago) parente6132f0
1 file changed+2−1
helix-term/src/commands.rs+2−1
helix-term/src/commands.rs+2−1
@@ -1250,7 +1250,8 @@ pub fn goto_mode(cx: &mut Context) {
12501250 // TODO: can't go to line 1 since we can't distinguish between g and 1g, g gets converted
12511251 // to 1g
12521252 let (view, doc) = cx.current();
1253− let pos = doc.text().line_to_char(count - 1);
1253+ let line_idx = std::cmp::min(count - 1, doc.text().len_lines().saturating_sub(2));
1254+ let pos = doc.text().line_to_char(line_idx);
12541255 doc.set_selection(view.id, Selection::point(pos));
12551256 return;
12561257 }