@@ -184,14 +184,10 @@ pub fn move_line_end(cx: &mut Context) {
184 let line = text.char_to_line(range.head);
184 let line = text.char_to_line(range.head);
186 // Line end is pos at the start of next line - 1
186 // Line end is pos at the start of next line - 1
187− // subtract 3 if the line ending is \r\n, otherwise subtract 2 as I assume all others are just 1 char length
187+ // subtract another 1 because the line ends with \n
188− let pos =
188+ let pos = text
189− text.line_to_char(line + 1)
189+ .line_to_char(line + 1)
190− .saturating_sub(if doc.line_ending == LineEnding::Crlf {
190+ .saturating_sub(doc.line_ending().len() + 1);
195 Range::new(pos, pos)
191 Range::new(pos, pos)
@@ -612,14 +608,10 @@ pub fn extend_line_end(cx: &mut Context) {
612 let line = text.char_to_line(range.head);
608 let line = text.char_to_line(range.head);
614 // Line end is pos at the start of next line - 1
610 // Line end is pos at the start of next line - 1
615− // subtract 3 if the line ending is \r\n, otherwise subtract 2 as I assume all others are just 1 char length
611+ // subtract another 1 because the line ends with \n
616− let pos =
612+ let pos = text
617− text.line_to_char(line + 1)
613+ .line_to_char(line + 1)
618− .saturating_sub(if doc.line_ending == LineEnding::Crlf {
614+ .saturating_sub(doc.line_ending().len() + 1);
623 Range::new(range.anchor, pos)
615 Range::new(range.anchor, pos)
@@ -908,7 +900,7 @@ pub fn append_mode(cx: &mut Context) {
908 if selection.iter().any(|range| range.head == end) {
900 if selection.iter().any(|range| range.head == end) {
909 let transaction = Transaction::change(
901 let transaction = Transaction::change(
910 doc.text(),
902 doc.text(),
911− std::array::IntoIter::new([(end, end, Some(Tendril::from_char('\n')))]), // TODO: change \n to doc.line_ending()
903+ std::array::IntoIter::new([(end, end, Some(doc.line_ending().as_str().into()))]),
913 doc.apply(&transaction, view.id);
905 doc.apply(&transaction, view.id);
@@ -1535,7 +1527,7 @@ fn open(cx: &mut Context, open: Open) {
1536 let indent = doc.indent_unit().repeat(indent_level);
1528 let indent = doc.indent_unit().repeat(indent_level);
1537 let mut text = String::with_capacity(1 + indent.len());
1529 let mut text = String::with_capacity(1 + indent.len());
1538− text.push_str(doc.line_ending());
1530+ text.push_str(doc.line_ending().as_str());
1539 text.push_str(&indent);
1531 text.push_str(&indent);
1540 let text = text.repeat(count);
1532 let text = text.repeat(count);
@@ -2143,7 +2135,7 @@ pub mod insert {
2144 let indent = doc.indent_unit().repeat(indent_level);
2136 let indent = doc.indent_unit().repeat(indent_level);
2145 let mut text = String::with_capacity(1 + indent.len());
2137 let mut text = String::with_capacity(1 + indent.len());
2146− text.push_str(doc.line_ending());
2138+ text.push_str(doc.line_ending().as_str());
2147 text.push_str(&indent);
2139 text.push_str(&indent);
2149 let head = pos + offs + text.chars().count();
2141 let head = pos + offs + text.chars().count();
@@ -2164,7 +2156,7 @@ pub mod insert {
2164 if helix_core::auto_pairs::PAIRS.contains(&(prev, curr)) {
2156 if helix_core::auto_pairs::PAIRS.contains(&(prev, curr)) {
2165 // another newline, indent the end bracket one level less
2157 // another newline, indent the end bracket one level less
2166 let indent = doc.indent_unit().repeat(indent_level.saturating_sub(1));
2158 let indent = doc.indent_unit().repeat(indent_level.saturating_sub(1));
2167− text.push_str(doc.line_ending());
2159+ text.push_str(doc.line_ending().as_str());
2168 text.push_str(&indent);
2160 text.push_str(&indent);
@@ -2283,7 +2275,7 @@ fn paste_impl(
2283 // if any of values ends \n it's linewise paste
2275 // if any of values ends \n it's linewise paste
2284 let linewise = values
2276 let linewise = values
2286− .any(|value| value.ends_with(doc.line_ending()));
2278+ .any(|value| value.ends_with(doc.line_ending().as_str()));
2288 let mut values = values.iter().cloned().map(Tendril::from).chain(repeat);
2280 let mut values = values.iter().cloned().map(Tendril::from).chain(repeat);