aboutsummaryrefslogtreecommitdiff
path: root/helix-term/src/commands
diff options
context:
space:
mode:
authorKirawi2022-04-23 08:01:08 +0000
committerGitHub2022-04-23 08:01:08 +0000
commitdd5a7c6191314b22347c323e8cda8aff225e21ba (patch)
treec9bb05eb7a15581a50d17b0ed930a5505784fd35 /helix-term/src/commands
parent5c2570582bdacf7acebf1bf4cab90699b98ecc67 (diff)
Replace line endings using `set_line_ending` command (#1871)
* set_line_ending: now replace line endings * use ending.len_chars() directly * account for unicode-lines feaure in line-ending doc
Diffstat (limited to 'helix-term/src/commands')
-rw-r--r--helix-term/src/commands/typed.rs23
1 files changed, 22 insertions, 1 deletions
diff --git a/helix-term/src/commands/typed.rs b/helix-term/src/commands/typed.rs
index 9a5298bb..d44bcf75 100644
--- a/helix-term/src/commands/typed.rs
+++ b/helix-term/src/commands/typed.rs
@@ -352,8 +352,26 @@ fn set_line_ending(
arg if arg.starts_with("nel") => Nel,
_ => bail!("invalid line ending"),
};
+ let (view, doc) = current!(cx.editor);
+ doc.line_ending = line_ending;
+
+ let mut pos = 0;
+ let transaction = Transaction::change(
+ doc.text(),
+ doc.text().lines().filter_map(|line| {
+ pos += line.len_chars();
+ match helix_core::line_ending::get_line_ending(&line) {
+ Some(ending) if ending != line_ending => {
+ let start = pos - ending.len_chars();
+ let end = pos;
+ Some((start, end, Some(line_ending.as_str().into())))
+ }
+ _ => None,
+ }
+ }),
+ );
+ doc.apply(&transaction, view.id);
- doc_mut!(cx.editor).line_ending = line_ending;
Ok(())
}
@@ -1193,6 +1211,9 @@ pub const TYPABLE_COMMAND_LIST: &[TypableCommand] = &[
TypableCommand {
name: "line-ending",
aliases: &[],
+ #[cfg(not(feature = "unicode-lines"))]
+ doc: "Set the document's default line ending. Options: crlf, lf.",
+ #[cfg(feature = "unicode-lines")]
doc: "Set the document's default line ending. Options: crlf, lf, cr, ff, nel.",
fun: set_line_ending,
completer: None,