@@ -4,9 +4,14 @@ use helix_core::{
44 movement::{self, Direction},
55 object, pos_at_coords,
66 regex::{self, Regex},
7+<<<<<<< HEAD
78 register::{self, Register, Registers},
89 search, selection, Change, ChangeSet, Position, Range, Rope, RopeSlice, Selection, SmallVec,
910 Tendril, Transaction,
11+=======
12+ register, search, selection, Change, ChangeSet, LineEnding, Position, Range, Rope, RopeSlice,
13+ Selection, SmallVec, Tendril, Transaction,
14+>>>>>>> 856fd95 (trying out line ending helper functions in commands.rs)
1015};
1116
1217use helix_view::{
@@ -184,8 +189,14 @@ pub fn move_line_end(cx: &mut Context) {
184189 let line = text.char_to_line(range.head);
185190
186191 // Line end is pos at the start of next line - 1
187− // subtract another 1 because the line ends with \n
188− let pos = text.line_to_char(line + 1).saturating_sub(2);
192+ // subtract 3 if the line ending is \r\n, otherwise subtract 2 as I assume all others are just 1 char length
193+ let pos =
194+ text.line_to_char(line + 1)
195+ .saturating_sub(if doc.line_ending == LineEnding::Crlf {
196+ 3
197+ } else {
198+ 2
199+ });
189200 Range::new(pos, pos)
190201 });
191202
@@ -337,7 +348,7 @@ where
337348 KeyEvent {
338349 code: KeyCode::Enter,
339350 ..
340− } => '\n',
351+ } => '\n', // TODO: we should be calling doc.line_ending() here
341352 KeyEvent {
342353 code: KeyCode::Char(ch),
343354 ..
@@ -465,7 +476,7 @@ pub fn replace(cx: &mut Context) {
465476 KeyEvent {
466477 code: KeyCode::Enter,
467478 ..
468− } => Some('\n'),
479+ } => Some('\n'), // TODO: we should be calling doc.line_ending() here
469480 _ => None,
470481 };
471482
@@ -606,8 +617,14 @@ pub fn extend_line_end(cx: &mut Context) {
606617 let line = text.char_to_line(range.head);
607618
608619 // Line end is pos at the start of next line - 1
609− // subtract another 1 because the line ends with \n
610− let pos = text.line_to_char(line + 1).saturating_sub(2);
620+ // subtract 3 if the line ending is \r\n, otherwise subtract 2 as I assume all others are just 1 char length
621+ let pos =
622+ text.line_to_char(line + 1)
623+ .saturating_sub(if doc.line_ending == LineEnding::Crlf {
624+ 3
625+ } else {
626+ 2
627+ });
611628 Range::new(range.anchor, pos)
612629 });
613630
@@ -896,7 +913,7 @@ pub fn append_mode(cx: &mut Context) {
896913 if selection.iter().any(|range| range.head == end) {
897914 let transaction = Transaction::change(
898915 doc.text(),
899− std::array::IntoIter::new([(end, end, Some(Tendril::from_char('\n')))]),
916+ std::array::IntoIter::new([(end, end, Some(Tendril::from_char('\n')))]), // TODO: change \n to doc.line_ending()
900917 );
901918 doc.apply(&transaction, view.id);
902919 }
@@ -1523,7 +1540,7 @@ fn open(cx: &mut Context, open: Open) {
15231540 );
15241541 let indent = doc.indent_unit().repeat(indent_level);
15251542 let mut text = String::with_capacity(1 + indent.len());
1526− text.push('\n');
1543+ text.push_str(doc.line_ending());
15271544 text.push_str(&indent);
15281545 let text = text.repeat(count);
15291546
@@ -2131,7 +2148,7 @@ pub mod insert {
21312148 );
21322149 let indent = doc.indent_unit().repeat(indent_level);
21332150 let mut text = String::with_capacity(1 + indent.len());
2134− text.push('\n');
2151+ text.push_str(doc.line_ending());
21352152 text.push_str(&indent);
21362153
21372154 let head = pos + offs + text.chars().count();
@@ -2152,7 +2169,7 @@ pub mod insert {
21522169 if helix_core::auto_pairs::PAIRS.contains(&(prev, curr)) {
21532170 // another newline, indent the end bracket one level less
21542171 let indent = doc.indent_unit().repeat(indent_level.saturating_sub(1));
2155− text.push('\n');
2172+ text.push_str(doc.line_ending());
21562173 text.push_str(&indent);
21572174 }
21582175
@@ -2268,8 +2285,15 @@ fn paste_impl(
22682285 .unwrap(),
22692286 );
22702287
2288+<<<<<<< HEAD
22712289 // if any of values ends \n it's linewise paste
22722290 let linewise = values.iter().any(|value| value.ends_with('\n'));
2291+=======
2292+ // if any of values ends \n it's linewise paste
2293+ let linewise = values
2294+ .iter()
2295+ .any(|value| value.ends_with(doc.line_ending()));
2296+>>>>>>> 856fd95 (trying out line ending helper functions in commands.rs)
22732297
22742298 let mut values = values.iter().cloned().map(Tendril::from).chain(repeat);
22752299