on master help sign in
Convert remaining commands to use the document's line ending setting.
commitd33355650fd53c05b4e3d4e0f421eaf013b5ea1e authorNathan Vegdahl <cessen@cessen.com> dateMon 21 Jun 2021, 11:59 (5 years ago) parente436c30
1 file changed+21−5
helix-term/src/commands.rs+21−5
helix-term/src/commands.rs+21−5
@@ -455,13 +455,27 @@ where
455455
456456 // need to wait for next key
457457 // TODO: should this be done by grapheme rather than char? For example,
458− // we can't properly handle the line-ending case here in terms of char.
458+ // we can't properly handle the line-ending CRLF case here in terms of char.
459459 cx.on_next_key(move |cx, event| {
460460 let ch = match event {
461461 KeyEvent {
462462 code: KeyCode::Enter,
463463 ..
464− } => '\n',
464+ } =>
465+ // TODO: this isn't quite correct when CRLF is involved.
466+ // This hack will work in most cases, since documents don't
467+ // usually mix line endings. But we should fix it eventually
468+ // anyway.
469+ {
470+ current!(cx.editor)
471+ .1
472+ .line_ending
473+ .as_str()
474+ .chars()
475+ .next()
476+ .unwrap()
477+ }
478+
465479 KeyEvent {
466480 code: KeyCode::Char(ch),
467481 ..
@@ -1289,7 +1303,8 @@ mod cmd {
12891303 }
12901304
12911305 fn yank_joined_to_clipboard(editor: &mut Editor, args: &[&str], _: PromptEvent) {
1292− let separator = args.first().copied().unwrap_or("\n");
1306+ let (_, doc) = current!(editor);
1307+ let separator = args.first().copied().unwrap_or(doc.line_ending.as_str());
12931308 yank_joined_to_clipboard_impl(editor, separator);
12941309 }
12951310
@@ -1745,7 +1760,7 @@ fn open(cx: &mut Context, open: Open) {
17451760 let indent = doc.indent_unit().repeat(indent_level);
17461761 let indent_len = indent.len();
17471762 let mut text = String::with_capacity(1 + indent_len);
1748− text.push('\n');
1763+ text.push_str(doc.line_ending.as_str());
17491764 text.push_str(&indent);
17501765 let text = text.repeat(count);
17511766
@@ -2502,7 +2517,8 @@ fn yank_joined_to_clipboard_impl(editor: &mut Editor, separator: &str) {
25022517}
25032518
25042519fn yank_joined_to_clipboard(cx: &mut Context) {
2505− yank_joined_to_clipboard_impl(&mut cx.editor, "\n");
2520+ let line_ending = current!(cx.editor).1.line_ending;
2521+ yank_joined_to_clipboard_impl(&mut cx.editor, line_ending.as_str());
25062522}
25072523
25082524fn yank_main_selection_to_clipboard_impl(editor: &mut Editor) {