| Line | Branch | Exec | Source |
|---|---|---|---|
| 1 | #include <stdlib.h> | ||
| 2 | #include <string.h> | ||
| 3 | #include "delete.h" | ||
| 4 | #include "buffer.h" | ||
| 5 | #include "change.h" | ||
| 6 | #include "indent.h" | ||
| 7 | #include "options.h" | ||
| 8 | #include "selection.h" | ||
| 9 | #include "util/string-view.h" | ||
| 10 | |||
| 11 | 9 | void delete_ch(View *view) | |
| 12 | { | ||
| 13 | 9 | size_t size = 0; | |
| 14 |
2/2✓ Branch 0 (2→3) taken 2 times.
✓ Branch 1 (2→5) taken 7 times.
|
9 | if (view->selection) { |
| 15 | 2 | size = prepare_selection(view); | |
| 16 | 2 | unselect(view); | |
| 17 | } else { | ||
| 18 | 7 | const LocalOptions *options = &view->buffer->options; | |
| 19 | 7 | begin_change(CHANGE_MERGE_DELETE); | |
| 20 |
2/2✓ Branch 0 (6→7) taken 4 times.
✓ Branch 1 (6→9) taken 3 times.
|
7 | if (options->emulate_tab) { |
| 21 | 4 | size = get_indent_level_bytes_right(options, &view->cursor); | |
| 22 | } | ||
| 23 |
1/2✓ Branch 0 (8→9) taken 4 times.
✗ Branch 1 (8→11) not taken.
|
4 | if (size == 0) { |
| 24 | 7 | BlockIter bi = view->cursor; | |
| 25 | 7 | size = block_iter_next_column(&bi); | |
| 26 | } | ||
| 27 | } | ||
| 28 | 9 | buffer_delete_bytes(view, size); | |
| 29 | 9 | } | |
| 30 | |||
| 31 | 6 | void erase(View *view) | |
| 32 | { | ||
| 33 | 6 | size_t size = 0; | |
| 34 |
2/2✓ Branch 0 (2→3) taken 1 times.
✓ Branch 1 (2→5) taken 5 times.
|
6 | if (view->selection) { |
| 35 | 1 | size = prepare_selection(view); | |
| 36 | 1 | unselect(view); | |
| 37 | } else { | ||
| 38 | 5 | const LocalOptions *options = &view->buffer->options; | |
| 39 | 5 | begin_change(CHANGE_MERGE_ERASE); | |
| 40 |
2/2✓ Branch 0 (6→7) taken 1 times.
✓ Branch 1 (6→10) taken 4 times.
|
5 | if (options->emulate_tab) { |
| 41 | 1 | size = get_indent_level_bytes_left(options, &view->cursor); | |
| 42 | 1 | block_iter_back_bytes(&view->cursor, size); | |
| 43 | } | ||
| 44 |
1/2✓ Branch 0 (9→10) taken 1 times.
✗ Branch 1 (9→12) not taken.
|
1 | if (size == 0) { |
| 45 | 5 | CodePoint u; | |
| 46 | 5 | size = block_iter_prev_char(&view->cursor, &u); | |
| 47 | } | ||
| 48 | } | ||
| 49 | 6 | buffer_erase_bytes(view, size); | |
| 50 | 6 | } | |
| 51 | |||
| 52 | 4 | void clear_lines(View *view, bool auto_indent) | |
| 53 | { | ||
| 54 | 4 | char *indent = NULL; | |
| 55 |
1/2✓ Branch 0 (2→3) taken 4 times.
✗ Branch 1 (2→11) not taken.
|
4 | if (auto_indent) { |
| 56 | 4 | BlockIter bi = view->cursor; | |
| 57 |
3/4✓ Branch 0 (4→5) taken 2 times.
✓ Branch 1 (4→10) taken 2 times.
✓ Branch 2 (6→7) taken 2 times.
✗ Branch 3 (6→10) not taken.
|
4 | if (block_iter_prev_line(&bi) && block_iter_find_non_empty_line_bwd(&bi)) { |
| 58 | 2 | StringView line = block_iter_get_line(&bi); | |
| 59 | 2 | indent = get_indent_for_next_line(&view->buffer->options, line); | |
| 60 | } | ||
| 61 | } | ||
| 62 | |||
| 63 | 4 | size_t del_count = 0; | |
| 64 |
2/2✓ Branch 0 (11→12) taken 1 times.
✓ Branch 1 (11→16) taken 3 times.
|
4 | if (view->selection) { |
| 65 | 1 | view->selection = SELECT_LINES; | |
| 66 | 1 | del_count = prepare_selection(view); | |
| 67 | 1 | unselect(view); | |
| 68 | // Don't delete last newline | ||
| 69 |
1/2✓ Branch 0 (14→15) taken 1 times.
✗ Branch 1 (14→18) not taken.
|
1 | if (del_count) { |
| 70 | 1 | del_count--; | |
| 71 | } | ||
| 72 | } else { | ||
| 73 | 3 | block_iter_eol(&view->cursor); | |
| 74 | 3 | del_count = block_iter_bol(&view->cursor); | |
| 75 | } | ||
| 76 | |||
| 77 |
1/2✓ Branch 0 (18→19) taken 4 times.
✗ Branch 1 (18→23) not taken.
|
4 | if (!indent && !del_count) { |
| 78 | return; | ||
| 79 | } | ||
| 80 | |||
| 81 |
2/2✓ Branch 0 (19→20) taken 2 times.
✓ Branch 1 (19→21) taken 2 times.
|
4 | size_t ins_count = indent ? strlen(indent) : 0; |
| 82 | 4 | buffer_replace_bytes(view, del_count, indent, ins_count); | |
| 83 | 4 | free(indent); | |
| 84 | 4 | block_iter_skip_bytes(&view->cursor, ins_count); | |
| 85 | } | ||
| 86 |