|
14 | 14 | #include "dged/buffers.h" |
15 | 15 | #include "dged/command.h" |
16 | 16 | #include "dged/display.h" |
| 17 | +#include "dged/location.h" |
17 | 18 | #include "dged/minibuffer.h" |
18 | 19 | #include "dged/path.h" |
19 | 20 | #include "dged/s8.h" |
20 | 21 | #include "dged/settings.h" |
| 22 | +#include "dged/text.h" |
21 | 23 | #include "dged/vec.h" |
22 | 24 | #include "dired.h" |
23 | 25 | #if defined(SYNTAX_ENABLE) |
@@ -109,7 +111,7 @@ int32_t run_interactive(struct command_ctx ctx, int argc, const char *argv[]) { |
109 | 111 | struct command *cmd = lookup_command(ctx.commands, argv[0]); |
110 | 112 | if (cmd != NULL) { |
111 | 113 | return execute_command(cmd, ctx.commands, ctx.active_window, ctx.buffers, |
112 | | - argc - 1, argv + 1); |
| 114 | + ctx.display, argc - 1, argv + 1); |
113 | 115 | } else { |
114 | 116 | minibuffer_echo_timeout(4, "command %s not found", argv[0]); |
115 | 117 | return 11; |
@@ -168,7 +170,8 @@ int32_t switch_buffer(struct command_ctx ctx, int argc, const char *argv[]) { |
168 | 170 | disable_completion(minibuffer_buffer()); |
169 | 171 |
|
170 | 172 | return execute_command(&do_switch_buffer_command, ctx.commands, |
171 | | - ctx.active_window, ctx.buffers, argc, argv); |
| 173 | + ctx.active_window, ctx.buffers, ctx.display, argc, |
| 174 | + argv); |
172 | 175 | } |
173 | 176 |
|
174 | 177 | int32_t do_kill_buffer(struct command_ctx ctx, int argc, const char *argv[]) { |
@@ -212,7 +215,8 @@ int32_t kill_buffer(struct command_ctx ctx, int argc, const char *argv[]) { |
212 | 215 | disable_completion(minibuffer_buffer()); |
213 | 216 |
|
214 | 217 | return execute_command(&do_switch_buffer_command, ctx.commands, |
215 | | - ctx.active_window, ctx.buffers, argc, argv); |
| 218 | + ctx.active_window, ctx.buffers, ctx.display, argc, |
| 219 | + argv); |
216 | 220 | } |
217 | 221 |
|
218 | 222 | static struct location draw_timer_value(struct buffer *buffer, double value, |
@@ -389,7 +393,8 @@ int32_t buflist_visit_cmd(struct command_ctx ctx, int argc, const char **argv) { |
389 | 393 | int32_t buflist_close_cmd(struct command_ctx ctx, int argc, |
390 | 394 | const char *argv[]) { |
391 | 395 | return execute_command(&do_switch_buffer_command, ctx.commands, |
392 | | - ctx.active_window, ctx.buffers, argc, argv); |
| 396 | + ctx.active_window, ctx.buffers, ctx.display, argc, |
| 397 | + argv); |
393 | 398 | } |
394 | 399 |
|
395 | 400 | void buflist_refresh(struct buffer *buffer, void *userdata) { |
@@ -439,7 +444,7 @@ int32_t buflist_kill_cmd(struct command_ctx ctx, int argc, const char *argv[]) { |
439 | 444 | buffers_remove(ctx.buffers, bufname); |
440 | 445 | free(bufname); |
441 | 446 | execute_command(&buflist_refresh_command, ctx.commands, ctx.active_window, |
442 | | - ctx.buffers, 0, NULL); |
| 447 | + ctx.buffers, ctx.display, 0, NULL); |
443 | 448 | } |
444 | 449 |
|
445 | 450 | return 0; |
@@ -468,7 +473,7 @@ int32_t buflist_save_cmd(struct command_ctx ctx, int argc, const char *argv[]) { |
468 | 473 | } |
469 | 474 | free(bufname); |
470 | 475 | execute_command(&buflist_refresh_command, ctx.commands, ctx.active_window, |
471 | | - ctx.buffers, 0, NULL); |
| 476 | + ctx.buffers, ctx.display, 0, NULL); |
472 | 477 | } |
473 | 478 |
|
474 | 479 | return 0; |
@@ -572,7 +577,7 @@ static int32_t open_file(struct command_ctx ctx, const char *pth) { |
572 | 577 | if (cmd != NULL) { |
573 | 578 | const char *argv[] = {pth}; |
574 | 579 | return execute_command(cmd, ctx.commands, ctx.active_window, ctx.buffers, |
575 | | - 1, argv); |
| 580 | + ctx.display, 1, argv); |
576 | 581 | } |
577 | 582 |
|
578 | 583 | minibuffer_echo_timeout(4, "dired is not supported"); |
@@ -777,14 +782,36 @@ BUFFER_VIEW_WRAPCMD(indent_alt) |
777 | 782 | BUFFER_VIEW_WRAPCMD(unindent_line) |
778 | 783 | BUFFER_VIEW_WRAPCMD(set_mark) |
779 | 784 | BUFFER_VIEW_WRAPCMD(clear_mark) |
780 | | -BUFFER_VIEW_WRAPCMD(copy) |
781 | 785 | BUFFER_VIEW_WRAPCMD(cut) |
782 | 786 | BUFFER_VIEW_WRAPCMD(paste) |
783 | 787 | BUFFER_VIEW_WRAPCMD(paste_older) |
784 | 788 | BUFFER_VIEW_WRAPCMD(goto_beginning) |
785 | 789 | BUFFER_VIEW_WRAPCMD(goto_end) |
786 | 790 | BUFFER_VIEW_WRAPCMD(sort_lines) |
787 | 791 |
|
| 792 | +static int32_t copy_cmd(struct command_ctx ctx, int argc, const char *argv[]) { |
| 793 | + (void)argc; |
| 794 | + (void)argv; |
| 795 | + struct buffer_view *bv = window_buffer_view(ctx.active_window); |
| 796 | + struct region reg = region_new(bv->dot, bv->mark); |
| 797 | + if (bv->mark_set && region_has_size(reg)) { |
| 798 | + /* send the copied text to the display. Display |
| 799 | + * in this case can mean X11/Wayland or terminal. |
| 800 | + * In the case of the terminal it uses OSC52. |
| 801 | + */ |
| 802 | + struct text_chunk txt = buffer_region(bv->buffer, reg); |
| 803 | + |
| 804 | + display_to_clipboard(ctx.display, |
| 805 | + (struct s8){.s = txt.text, .l = txt.nbytes}); |
| 806 | + if (txt.allocated) { |
| 807 | + free(txt.text); |
| 808 | + } |
| 809 | + } |
| 810 | + |
| 811 | + buffer_view_copy(bv); |
| 812 | + return 0; |
| 813 | +} |
| 814 | + |
788 | 815 | static int32_t undo_cmd(struct command_ctx ctx, int argc, const char *argv[]) { |
789 | 816 | (void)argc; |
790 | 817 | (void)argv; |
|
0 commit comments