Skip to content

Commit

Permalink
Limit goto count
Browse files Browse the repository at this point in the history
Giving a goto count greater than the number of lines in the buffer
would cause Helix to panic.
  • Loading branch information
hovsater authored and archseer committed Jun 3, 2021
1 parent e6132f0 commit fdb5bfa
Showing 1 changed file with 2 additions and 1 deletion.
3 changes: 2 additions & 1 deletion helix-term/src/commands.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1250,7 +1250,8 @@ pub fn goto_mode(cx: &mut Context) {
// TODO: can't go to line 1 since we can't distinguish between g and 1g, g gets converted
// to 1g
let (view, doc) = cx.current();
let pos = doc.text().line_to_char(count - 1);
let line_idx = std::cmp::min(count - 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));
return;
}
Expand Down

0 comments on commit fdb5bfa

Please sign in to comment.