diff options
author | Blaž Hrastnik | 2021-06-23 15:50:52 +0000 |
---|---|---|
committer | Blaž Hrastnik | 2021-06-23 15:50:52 +0000 |
commit | 655c1aeb73256c2f74abd1d251b04909d8251f37 (patch) | |
tree | b4a791ef081e641529ab01c1c4d79396bdca4bd6 | |
parent | ea8cd4765d8be374e6c5cddc6cdcff27c77f677c (diff) |
fix: panic on O at the start of the file (fixes #354)
-rw-r--r-- | helix-term/src/commands.rs | 7 |
1 files changed, 4 insertions, 3 deletions
diff --git a/helix-term/src/commands.rs b/helix-term/src/commands.rs index cf583953..941dc9a3 100644 --- a/helix-term/src/commands.rs +++ b/helix-term/src/commands.rs @@ -1826,10 +1826,11 @@ fn open(cx: &mut Context, open: Open) { }; // insert newlines after this index for both Above and Below variants - let linend_index = doc.text().line_to_char(line) - - get_line_ending(&doc.text().line(line)) + let linend_index = doc.text().line_to_char(line).saturating_sub( + get_line_ending(&doc.text().line(line)) .map(|le| le.len_chars()) - .unwrap_or(0); + .unwrap_or(0), + ); // TODO: share logic with insert_newline for indentation let indent_level = indent::suggested_indent_for_pos( |