aboutsummaryrefslogtreecommitdiff
path: root/helix-term/src
diff options
context:
space:
mode:
authorBlaž Hrastnik2021-06-23 15:58:14 +0000
committerBlaž Hrastnik2021-06-23 15:58:14 +0000
commit4ad7b61c695b9e4fb195258b80f184759ad6560e (patch)
tree09085867b67eed6eacef47fa572a2a8f699c7dae /helix-term/src
parent655c1aeb73256c2f74abd1d251b04909d8251f37 (diff)
fix: Better fix that also fixes crashes on `o`
Diffstat (limited to 'helix-term/src')
-rw-r--r--helix-term/src/commands.rs12
1 files changed, 4 insertions, 8 deletions
diff --git a/helix-term/src/commands.rs b/helix-term/src/commands.rs
index 941dc9a3..8f36a666 100644
--- a/helix-term/src/commands.rs
+++ b/helix-term/src/commands.rs
@@ -1826,18 +1826,14 @@ 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).saturating_sub(
- get_line_ending(&doc.text().line(line))
- .map(|le| le.len_chars())
- .unwrap_or(0),
- );
+ let line_end_index = rope_end_without_line_ending(&doc.text().slice(..));
// TODO: share logic with insert_newline for indentation
let indent_level = indent::suggested_indent_for_pos(
doc.language_config(),
doc.syntax(),
text,
- linend_index,
+ line_end_index,
true,
);
let indent = doc.indent_unit().repeat(indent_level);
@@ -1851,7 +1847,7 @@ fn open(cx: &mut Context, open: Open) {
let pos = if line == 0 {
0 // Required since text will have a min len of 1 (\n)
} else {
- offs + linend_index + 1
+ offs + line_end_index + 1
};
for i in 0..count {
// pos -> beginning of reference line,
@@ -1862,7 +1858,7 @@ fn open(cx: &mut Context, open: Open) {
offs += text.chars().count();
- (linend_index, linend_index, Some(text.into()))
+ (line_end_index, line_end_index, Some(text.into()))
});
transaction = transaction.with_selection(Selection::new(ranges, selection.primary_index()));