on master help sign in
Fix open-new-line command for CRLF, as well as other bugs.
8935e7aNathan Vegdahl
helix-term/src/commands.rs+11−7
@@ -1825,8 +1825,16 @@ fn open(cx: &mut Context, open: Open) {
1825 Open::Above => line,
1825 Open::Above => line,
1826 };
1826 };
1827
1827
1828− // insert newlines after this index for both Above and Below variants
1828+ // Index to insert newlines after, as well as the char width
1829+ // to use to compensate for those inserted newlines.
1830+ let (line_end_index, line_end_offset_width) = if line == 0 {
1831+ (0, 0)
1832+ } else {
1833+ (
1829− let line_end_index = line_end_char_index(&doc.text().slice(..), line.saturating_sub(1));
1834+ line_end_char_index(&doc.text().slice(..), line.saturating_sub(1)),
1835+ doc.line_ending.len_chars(),
1836+ )
1837+ };
1830
1838
1831 // TODO: share logic with insert_newline for indentation
1839 // TODO: share logic with insert_newline for indentation
1832 let indent_level = indent::suggested_indent_for_pos(
1840 let indent_level = indent::suggested_indent_for_pos(
@@ -1844,11 +1852,7 @@ fn open(cx: &mut Context, open: Open) {
1844 let text = text.repeat(count);
1852 let text = text.repeat(count);
1845
1853
1846 // calculate new selection ranges
1854 // calculate new selection ranges
1847− let pos = if line == 0 {
1848− 0 // Required since text will have a min len of 1 (\n)
1849− } else {
1850− offs + line_end_index + 1
1855+ let pos = offs + line_end_index + line_end_offset_width;
1851− };
1852 for i in 0..count {
1856 for i in 0..count {
1853 // pos -> beginning of reference line,
1857 // pos -> beginning of reference line,
1854 // + (i * (1+indent_len)) -> beginning of i'th line from pos
1858 // + (i * (1+indent_len)) -> beginning of i'th line from pos