aboutsummaryrefslogtreecommitdiff
path: root/helix-term/src/commands.rs
diff options
context:
space:
mode:
authorKevin Sjöberg2021-06-03 14:43:28 +0000
committerBlaž Hrastnik2021-06-03 16:35:52 +0000
commitfdb5bfafaec05f64f2e759717aade5131496557b (patch)
treefc3bcb4c019f75c1041c0f70da91f6afcd6c233d /helix-term/src/commands.rs
parente6132f0acdee8bfa542cd7f7571aeae702ac21a8 (diff)
Limit goto count
Giving a goto count greater than the number of lines in the buffer would cause Helix to panic.
Diffstat (limited to 'helix-term/src/commands.rs')
-rw-r--r--helix-term/src/commands.rs3
1 files changed, 2 insertions, 1 deletions
diff --git a/helix-term/src/commands.rs b/helix-term/src/commands.rs
index 4a4816a0..35f1f0cd 100644
--- a/helix-term/src/commands.rs
+++ b/helix-term/src/commands.rs
@@ -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;
}