|
|
@ -4,9 +4,14 @@ use helix_core::{
|
|
|
|
movement::{self, Direction},
|
|
|
|
movement::{self, Direction},
|
|
|
|
object, pos_at_coords,
|
|
|
|
object, pos_at_coords,
|
|
|
|
regex::{self, Regex},
|
|
|
|
regex::{self, Regex},
|
|
|
|
|
|
|
|
<<<<<<< HEAD
|
|
|
|
register::{self, Register, Registers},
|
|
|
|
register::{self, Register, Registers},
|
|
|
|
search, selection, Change, ChangeSet, Position, Range, Rope, RopeSlice, Selection, SmallVec,
|
|
|
|
search, selection, Change, ChangeSet, Position, Range, Rope, RopeSlice, Selection, SmallVec,
|
|
|
|
Tendril, Transaction,
|
|
|
|
Tendril, Transaction,
|
|
|
|
|
|
|
|
=======
|
|
|
|
|
|
|
|
register, search, selection, Change, ChangeSet, LineEnding, Position, Range, Rope, RopeSlice,
|
|
|
|
|
|
|
|
Selection, SmallVec, Tendril, Transaction,
|
|
|
|
|
|
|
|
>>>>>>> 856fd95 (trying out line ending helper functions in commands.rs)
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
use helix_view::{
|
|
|
|
use helix_view::{
|
|
|
@ -184,8 +189,14 @@ pub fn move_line_end(cx: &mut Context) {
|
|
|
|
let line = text.char_to_line(range.head);
|
|
|
|
let line = text.char_to_line(range.head);
|
|
|
|
|
|
|
|
|
|
|
|
// Line end is pos at the start of next line - 1
|
|
|
|
// Line end is pos at the start of next line - 1
|
|
|
|
// subtract another 1 because the line ends with \n
|
|
|
|
// subtract 3 if the line ending is \r\n, otherwise subtract 2 as I assume all others are just 1 char length
|
|
|
|
let pos = text.line_to_char(line + 1).saturating_sub(2);
|
|
|
|
let pos =
|
|
|
|
|
|
|
|
text.line_to_char(line + 1)
|
|
|
|
|
|
|
|
.saturating_sub(if doc.line_ending == LineEnding::Crlf {
|
|
|
|
|
|
|
|
3
|
|
|
|
|
|
|
|
} else {
|
|
|
|
|
|
|
|
2
|
|
|
|
|
|
|
|
});
|
|
|
|
Range::new(pos, pos)
|
|
|
|
Range::new(pos, pos)
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
@ -337,7 +348,7 @@ where
|
|
|
|
KeyEvent {
|
|
|
|
KeyEvent {
|
|
|
|
code: KeyCode::Enter,
|
|
|
|
code: KeyCode::Enter,
|
|
|
|
..
|
|
|
|
..
|
|
|
|
} => '\n',
|
|
|
|
} => '\n', // TODO: we should be calling doc.line_ending() here
|
|
|
|
KeyEvent {
|
|
|
|
KeyEvent {
|
|
|
|
code: KeyCode::Char(ch),
|
|
|
|
code: KeyCode::Char(ch),
|
|
|
|
..
|
|
|
|
..
|
|
|
@ -465,7 +476,7 @@ pub fn replace(cx: &mut Context) {
|
|
|
|
KeyEvent {
|
|
|
|
KeyEvent {
|
|
|
|
code: KeyCode::Enter,
|
|
|
|
code: KeyCode::Enter,
|
|
|
|
..
|
|
|
|
..
|
|
|
|
} => Some('\n'),
|
|
|
|
} => Some('\n'), // TODO: we should be calling doc.line_ending() here
|
|
|
|
_ => None,
|
|
|
|
_ => None,
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
@ -606,8 +617,14 @@ pub fn extend_line_end(cx: &mut Context) {
|
|
|
|
let line = text.char_to_line(range.head);
|
|
|
|
let line = text.char_to_line(range.head);
|
|
|
|
|
|
|
|
|
|
|
|
// Line end is pos at the start of next line - 1
|
|
|
|
// Line end is pos at the start of next line - 1
|
|
|
|
// subtract another 1 because the line ends with \n
|
|
|
|
// subtract 3 if the line ending is \r\n, otherwise subtract 2 as I assume all others are just 1 char length
|
|
|
|
let pos = text.line_to_char(line + 1).saturating_sub(2);
|
|
|
|
let pos =
|
|
|
|
|
|
|
|
text.line_to_char(line + 1)
|
|
|
|
|
|
|
|
.saturating_sub(if doc.line_ending == LineEnding::Crlf {
|
|
|
|
|
|
|
|
3
|
|
|
|
|
|
|
|
} else {
|
|
|
|
|
|
|
|
2
|
|
|
|
|
|
|
|
});
|
|
|
|
Range::new(range.anchor, pos)
|
|
|
|
Range::new(range.anchor, pos)
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
@ -896,7 +913,7 @@ pub fn append_mode(cx: &mut Context) {
|
|
|
|
if selection.iter().any(|range| range.head == end) {
|
|
|
|
if selection.iter().any(|range| range.head == end) {
|
|
|
|
let transaction = Transaction::change(
|
|
|
|
let transaction = Transaction::change(
|
|
|
|
doc.text(),
|
|
|
|
doc.text(),
|
|
|
|
std::array::IntoIter::new([(end, end, Some(Tendril::from_char('\n')))]),
|
|
|
|
std::array::IntoIter::new([(end, end, Some(Tendril::from_char('\n')))]), // TODO: change \n to doc.line_ending()
|
|
|
|
);
|
|
|
|
);
|
|
|
|
doc.apply(&transaction, view.id);
|
|
|
|
doc.apply(&transaction, view.id);
|
|
|
|
}
|
|
|
|
}
|
|
|
@ -1523,7 +1540,7 @@ fn open(cx: &mut Context, open: Open) {
|
|
|
|
);
|
|
|
|
);
|
|
|
|
let indent = doc.indent_unit().repeat(indent_level);
|
|
|
|
let indent = doc.indent_unit().repeat(indent_level);
|
|
|
|
let mut text = String::with_capacity(1 + indent.len());
|
|
|
|
let mut text = String::with_capacity(1 + indent.len());
|
|
|
|
text.push('\n');
|
|
|
|
text.push_str(doc.line_ending());
|
|
|
|
text.push_str(&indent);
|
|
|
|
text.push_str(&indent);
|
|
|
|
let text = text.repeat(count);
|
|
|
|
let text = text.repeat(count);
|
|
|
|
|
|
|
|
|
|
|
@ -2131,7 +2148,7 @@ pub mod insert {
|
|
|
|
);
|
|
|
|
);
|
|
|
|
let indent = doc.indent_unit().repeat(indent_level);
|
|
|
|
let indent = doc.indent_unit().repeat(indent_level);
|
|
|
|
let mut text = String::with_capacity(1 + indent.len());
|
|
|
|
let mut text = String::with_capacity(1 + indent.len());
|
|
|
|
text.push('\n');
|
|
|
|
text.push_str(doc.line_ending());
|
|
|
|
text.push_str(&indent);
|
|
|
|
text.push_str(&indent);
|
|
|
|
|
|
|
|
|
|
|
|
let head = pos + offs + text.chars().count();
|
|
|
|
let head = pos + offs + text.chars().count();
|
|
|
@ -2152,7 +2169,7 @@ pub mod insert {
|
|
|
|
if helix_core::auto_pairs::PAIRS.contains(&(prev, curr)) {
|
|
|
|
if helix_core::auto_pairs::PAIRS.contains(&(prev, curr)) {
|
|
|
|
// another newline, indent the end bracket one level less
|
|
|
|
// another newline, indent the end bracket one level less
|
|
|
|
let indent = doc.indent_unit().repeat(indent_level.saturating_sub(1));
|
|
|
|
let indent = doc.indent_unit().repeat(indent_level.saturating_sub(1));
|
|
|
|
text.push('\n');
|
|
|
|
text.push_str(doc.line_ending());
|
|
|
|
text.push_str(&indent);
|
|
|
|
text.push_str(&indent);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
@ -2268,8 +2285,15 @@ fn paste_impl(
|
|
|
|
.unwrap(),
|
|
|
|
.unwrap(),
|
|
|
|
);
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
<<<<<<< HEAD
|
|
|
|
// if any of values ends \n it's linewise paste
|
|
|
|
// if any of values ends \n it's linewise paste
|
|
|
|
let linewise = values.iter().any(|value| value.ends_with('\n'));
|
|
|
|
let linewise = values.iter().any(|value| value.ends_with('\n'));
|
|
|
|
|
|
|
|
=======
|
|
|
|
|
|
|
|
// if any of values ends \n it's linewise paste
|
|
|
|
|
|
|
|
let linewise = values
|
|
|
|
|
|
|
|
.iter()
|
|
|
|
|
|
|
|
.any(|value| value.ends_with(doc.line_ending()));
|
|
|
|
|
|
|
|
>>>>>>> 856fd95 (trying out line ending helper functions in commands.rs)
|
|
|
|
|
|
|
|
|
|
|
|
let mut values = values.iter().cloned().map(Tendril::from).chain(repeat);
|
|
|
|
let mut values = values.iter().cloned().map(Tendril::from).chain(repeat);
|
|
|
|
|
|
|
|
|
|
|
|