summaryrefslogtreecommitdiff
path: root/helix-term/src
diff options
context:
space:
mode:
authorNathan Vegdahl2021-06-21 18:59:03 +0000
committerNathan Vegdahl2021-06-21 18:59:03 +0000
commitd33355650fd53c05b4e3d4e0f421eaf013b5ea1e (patch)
treeaa162de83ac688dcb6b161adc8d3b104dcd2ab4d /helix-term/src
parente436c30ed7df303a32455c4cf9e0574ab87c0683 (diff)
Convert remaining commands to use the document's line ending setting.
Diffstat (limited to 'helix-term/src')
-rw-r--r--helix-term/src/commands.rs26
1 files changed, 21 insertions, 5 deletions
diff --git a/helix-term/src/commands.rs b/helix-term/src/commands.rs
index dc7f8913..6ccbaaff 100644
--- a/helix-term/src/commands.rs
+++ b/helix-term/src/commands.rs
@@ -455,13 +455,27 @@ where
// need to wait for next key
// TODO: should this be done by grapheme rather than char? For example,
- // we can't properly handle the line-ending case here in terms of char.
+ // we can't properly handle the line-ending CRLF case here in terms of char.
cx.on_next_key(move |cx, event| {
let ch = match event {
KeyEvent {
code: KeyCode::Enter,
..
- } => '\n',
+ } =>
+ // TODO: this isn't quite correct when CRLF is involved.
+ // This hack will work in most cases, since documents don't
+ // usually mix line endings. But we should fix it eventually
+ // anyway.
+ {
+ current!(cx.editor)
+ .1
+ .line_ending
+ .as_str()
+ .chars()
+ .next()
+ .unwrap()
+ }
+
KeyEvent {
code: KeyCode::Char(ch),
..
@@ -1289,7 +1303,8 @@ mod cmd {
}
fn yank_joined_to_clipboard(editor: &mut Editor, args: &[&str], _: PromptEvent) {
- let separator = args.first().copied().unwrap_or("\n");
+ let (_, doc) = current!(editor);
+ let separator = args.first().copied().unwrap_or(doc.line_ending.as_str());
yank_joined_to_clipboard_impl(editor, separator);
}
@@ -1745,7 +1760,7 @@ fn open(cx: &mut Context, open: Open) {
let indent = doc.indent_unit().repeat(indent_level);
let indent_len = indent.len();
let mut text = String::with_capacity(1 + indent_len);
- text.push('\n');
+ text.push_str(doc.line_ending.as_str());
text.push_str(&indent);
let text = text.repeat(count);
@@ -2502,7 +2517,8 @@ fn yank_joined_to_clipboard_impl(editor: &mut Editor, separator: &str) {
}
fn yank_joined_to_clipboard(cx: &mut Context) {
- yank_joined_to_clipboard_impl(&mut cx.editor, "\n");
+ let line_ending = current!(cx.editor).1.line_ending;
+ yank_joined_to_clipboard_impl(&mut cx.editor, line_ending.as_str());
}
fn yank_main_selection_to_clipboard_impl(editor: &mut Editor) {