@@ -455,13 +455,27 @@ where
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,
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
465 KeyEvent {
479 KeyEvent {
466 code: KeyCode::Char(ch),
480 code: KeyCode::Char(ch),
@@ -1289,7 +1303,8 @@ mod cmd {
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);
@@ -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);
@@ -2502,7 +2517,8 @@ fn yank_joined_to_clipboard_impl(editor: &mut Editor, separator: &str) {
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());
2508fn yank_main_selection_to_clipboard_impl(editor: &mut Editor) {
2524fn yank_main_selection_to_clipboard_impl(editor: &mut Editor) {