src/copy.c
| Line | Branch | Exec | Source |
|---|---|---|---|
| 1 | #include "copy.h" | ||
| 2 | #include "block-iter.h" | ||
| 3 | #include "change.h" | ||
| 4 | #include "insert.h" | ||
| 5 | #include "move.h" | ||
| 6 | #include "selection.h" | ||
| 7 | |||
| 8 | 6 | void paste(Clipboard *clip, View *view, PasteLinesType type, bool move_after) | |
| 9 | { | ||
| 10 |
1/2✓ Branch 2 → 3 taken 6 times.
✗ Branch 2 → 25 not taken.
|
6 | if (clip->len == 0) { |
| 11 | 2 | return; | |
| 12 | } | ||
| 13 | |||
| 14 | 6 | BUG_ON(!clip->buf); | |
| 15 | 6 | StringView text = string_view(clip->buf, clip->len); | |
| 16 | |||
| 17 |
4/4✓ Branch 5 → 6 taken 5 times.
✓ Branch 5 → 7 taken 1 time.
✓ Branch 6 → 7 taken 1 time.
✓ Branch 6 → 8 taken 4 times.
|
6 | if (!clip->is_lines || type == PASTE_LINES_INLINE) { |
| 18 | 2 | insert_text(view, text, move_after); | |
| 19 | 2 | return; | |
| 20 | } | ||
| 21 | |||
| 22 | 4 | size_t del_count = 0; | |
| 23 |
1/2✗ Branch 8 → 9 not taken.
✓ Branch 8 → 11 taken 4 times.
|
4 | if (view->selection) { |
| 24 | ✗ | del_count = prepare_selection(view); | |
| 25 | ✗ | unselect(view); | |
| 26 | } | ||
| 27 | |||
| 28 | 4 | const long x = view_get_preferred_x(view); | |
| 29 |
1/2✓ Branch 12 → 13 taken 4 times.
✗ Branch 12 → 18 not taken.
|
4 | if (!del_count) { |
| 30 |
1/2✓ Branch 13 → 14 taken 4 times.
✗ Branch 13 → 15 not taken.
|
4 | if (type == PASTE_LINES_BELOW_CURSOR) { |
| 31 | 4 | block_iter_eat_line(&view->cursor); | |
| 32 | } else { | ||
| 33 | ✗ | BUG_ON(type != PASTE_LINES_ABOVE_CURSOR); | |
| 34 | ✗ | block_iter_bol(&view->cursor); | |
| 35 | } | ||
| 36 | } | ||
| 37 | |||
| 38 | 4 | buffer_replace_bytes(view, del_count, text); | |
| 39 | |||
| 40 |
1/2✗ Branch 19 → 20 not taken.
✓ Branch 19 → 21 taken 4 times.
|
4 | if (move_after) { |
| 41 | ✗ | block_iter_skip_bytes(&view->cursor, clip->len); | |
| 42 | } else { | ||
| 43 | // Try to keep cursor column | ||
| 44 | 4 | move_to_preferred_x(view, x); | |
| 45 | } | ||
| 46 | |||
| 47 | // New preferred_x | ||
| 48 | 4 | view_reset_preferred_x(view); | |
| 49 | } | ||
| 50 |