diff options
| author | Mitja Felicijan <mitja.felicijan@gmail.com> | 2026-01-21 22:52:54 +0100 |
|---|---|---|
| committer | Mitja Felicijan <mitja.felicijan@gmail.com> | 2026-01-21 22:52:54 +0100 |
| commit | dcacc00e3750300617ba6e16eb346713f91a783a (patch) | |
| tree | 38e2d4fb5ed9d119711d4295c6eda4b014af73fd /examples/dte/copy.c | |
| parent | 58dac10aeb8f5a041c46bddbeaf4c7966a99b998 (diff) | |
| download | crep-dcacc00e3750300617ba6e16eb346713f91a783a.tar.gz | |
Remove testing data
Diffstat (limited to 'examples/dte/copy.c')
| -rw-r--r-- | examples/dte/copy.c | 74 |
1 files changed, 0 insertions, 74 deletions
diff --git a/examples/dte/copy.c b/examples/dte/copy.c deleted file mode 100644 index c3b989e..0000000 --- a/examples/dte/copy.c +++ /dev/null | |||
| @@ -1,74 +0,0 @@ | |||
| 1 | #include <stdlib.h> | ||
| 2 | #include "copy.h" | ||
| 3 | #include "block-iter.h" | ||
| 4 | #include "change.h" | ||
| 5 | #include "misc.h" | ||
| 6 | #include "move.h" | ||
| 7 | #include "selection.h" | ||
| 8 | #include "util/debug.h" | ||
| 9 | |||
| 10 | void record_copy(Clipboard *clip, char *buf, size_t len, bool is_lines) | ||
| 11 | { | ||
| 12 | BUG_ON(len && !buf); | ||
| 13 | free(clip->buf); | ||
| 14 | clip->buf = buf; | ||
| 15 | clip->len = len; | ||
| 16 | clip->is_lines = is_lines; | ||
| 17 | } | ||
| 18 | |||
| 19 | void copy(Clipboard *clip, View *view, size_t len, bool is_lines) | ||
| 20 | { | ||
| 21 | if (len) { | ||
| 22 | char *buf = block_iter_get_bytes(&view->cursor, len); | ||
| 23 | record_copy(clip, buf, len, is_lines); | ||
| 24 | } | ||
| 25 | } | ||
| 26 | |||
| 27 | void cut(Clipboard *clip, View *view, size_t len, bool is_lines) | ||
| 28 | { | ||
| 29 | if (len) { | ||
| 30 | copy(clip, view, len, is_lines); | ||
| 31 | buffer_delete_bytes(view, len); | ||
| 32 | } | ||
| 33 | } | ||
| 34 | |||
| 35 | void paste(Clipboard *clip, View *view, PasteLinesType type, bool move_after) | ||
| 36 | { | ||
| 37 | if (clip->len == 0) { | ||
| 38 | return; | ||
| 39 | } | ||
| 40 | |||
| 41 | BUG_ON(!clip->buf); | ||
| 42 | if (!clip->is_lines || type == PASTE_LINES_INLINE) { | ||
| 43 | insert_text(view, clip->buf, clip->len, move_after); | ||
| 44 | return; | ||
| 45 | } | ||
| 46 | |||
| 47 | size_t del_count = 0; | ||
| 48 | if (view->selection) { | ||
| 49 | del_count = prepare_selection(view); | ||
| 50 | unselect(view); | ||
| 51 | } | ||
| 52 | |||
| 53 | const long x = view_get_preferred_x(view); | ||
| 54 | if (!del_count) { | ||
| 55 | if (type == PASTE_LINES_BELOW_CURSOR) { | ||
| 56 | block_iter_eat_line(&view->cursor); | ||
| 57 | } else { | ||
| 58 | BUG_ON(type != PASTE_LINES_ABOVE_CURSOR); | ||
| 59 | block_iter_bol(&view->cursor); | ||
| 60 | } | ||
| 61 | } | ||
| 62 | |||
| 63 | buffer_replace_bytes(view, del_count, clip->buf, clip->len); | ||
| 64 | |||
| 65 | if (move_after) { | ||
| 66 | block_iter_skip_bytes(&view->cursor, clip->len); | ||
| 67 | } else { | ||
| 68 | // Try to keep cursor column | ||
| 69 | move_to_preferred_x(view, x); | ||
| 70 | } | ||
| 71 | |||
| 72 | // New preferred_x | ||
| 73 | view_reset_preferred_x(view); | ||
| 74 | } | ||
