on master help sign in
Convert remaining commands to use the document's line ending setting.
d333556Nathan Vegdahl
helix-term/src/commands.rs+21−5
@@ -455,13 +455,27 @@ where
455
455
456 // need to wait for next key
456 // need to wait for next key
457 // TODO: should this be done by grapheme rather than char? For example,
457 // 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.
459 cx.on_next_key(move |cx, event| {
459 cx.on_next_key(move |cx, event| {
460 let ch = match event {
460 let ch = match event {
461 KeyEvent {
461 KeyEvent {
462 code: KeyCode::Enter,
462 code: KeyCode::Enter,
463 ..
463 ..
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+
465 KeyEvent {
479 KeyEvent {
466 code: KeyCode::Char(ch),
480 code: KeyCode::Char(ch),
467 ..
481 ..
@@ -1289,7 +1303,8 @@ mod cmd {
1289 }
1303 }
1290
1304
1291 fn yank_joined_to_clipboard(editor: &mut Editor, args: &[&str], _: PromptEvent) {
1305 fn yank_joined_to_clipboard(editor: &mut Editor, args: &[&str], _: PromptEvent) {
1306+ let (_, doc) = current!(editor);
1292− let separator = args.first().copied().unwrap_or("\n");
1307+ let separator = args.first().copied().unwrap_or(doc.line_ending.as_str());
1293 yank_joined_to_clipboard_impl(editor, separator);
1308 yank_joined_to_clipboard_impl(editor, separator);
1294 }
1309 }
1295
1310
@@ -1745,7 +1760,7 @@ fn open(cx: &mut Context, open: Open) {
1745 let indent = doc.indent_unit().repeat(indent_level);
1760 let indent = doc.indent_unit().repeat(indent_level);
1746 let indent_len = indent.len();
1761 let indent_len = indent.len();
1747 let mut text = String::with_capacity(1 + indent_len);
1762 let mut text = String::with_capacity(1 + indent_len);
1748− text.push('\n');
1763+ text.push_str(doc.line_ending.as_str());
1749 text.push_str(&indent);
1764 text.push_str(&indent);
1750 let text = text.repeat(count);
1765 let text = text.repeat(count);
1751
1766
@@ -2502,7 +2517,8 @@ fn yank_joined_to_clipboard_impl(editor: &mut Editor, separator: &str) {
2502}
2517}
2503
2518
2504fn yank_joined_to_clipboard(cx: &mut Context) {
2519fn yank_joined_to_clipboard(cx: &mut Context) {
2520+ let line_ending = current!(cx.editor).1.line_ending;
2505− yank_joined_to_clipboard_impl(&mut cx.editor, "\n");
2521+ yank_joined_to_clipboard_impl(&mut cx.editor, line_ending.as_str());
2506}
2522}
2507
2523
2508fn yank_main_selection_to_clipboard_impl(editor: &mut Editor) {
2524fn yank_main_selection_to_clipboard_impl(editor: &mut Editor) {