on master help sign in
fix: Better fix that also fixes crashes on `o`
commit4ad7b61c695b9e4fb195258b80f184759ad6560e authorBlaž Hrastnik <blaz@mxxn.io> dateThu 24 Jun 2021, 00:58 (5 years ago) parent655c1ae
1 file changed+4−8
helix-term/src/commands.rs+4−8
helix-term/src/commands.rs+4−8
@@ -1826,18 +1826,14 @@ fn open(cx: &mut Context, open: Open) {
18261826 };
18271827
18281828 // insert newlines after this index for both Above and Below variants
1829− let linend_index = doc.text().line_to_char(line).saturating_sub(
1830− get_line_ending(&doc.text().line(line))
1831− .map(|le| le.len_chars())
1832− .unwrap_or(0),
1833− );
1829+ let line_end_index = rope_end_without_line_ending(&doc.text().slice(..));
18341830
18351831 // TODO: share logic with insert_newline for indentation
18361832 let indent_level = indent::suggested_indent_for_pos(
18371833 doc.language_config(),
18381834 doc.syntax(),
18391835 text,
1840− linend_index,
1836+ line_end_index,
18411837 true,
18421838 );
18431839 let indent = doc.indent_unit().repeat(indent_level);
@@ -1851,7 +1847,7 @@ fn open(cx: &mut Context, open: Open) {
18511847 let pos = if line == 0 {
18521848 0 // Required since text will have a min len of 1 (\n)
18531849 } else {
1854− offs + linend_index + 1
1850+ offs + line_end_index + 1
18551851 };
18561852 for i in 0..count {
18571853 // pos -> beginning of reference line,
@@ -1862,7 +1858,7 @@ fn open(cx: &mut Context, open: Open) {
18621858
18631859 offs += text.chars().count();
18641860
1865− (linend_index, linend_index, Some(text.into()))
1861+ (line_end_index, line_end_index, Some(text.into()))
18661862 });
18671863
18681864 transaction = transaction.with_selection(Selection::new(ranges, selection.primary_index()));