diff options
author | KatolaZ <katolaz@freaknet.org> | 2019-07-31 11:19:55 +0100 |
---|---|---|
committer | KatolaZ <katolaz@freaknet.org> | 2019-07-31 11:19:55 +0100 |
commit | f3100ddd486d6f39b0c97c9c492bb6020bf3caf1 (patch) | |
tree | 729407153bc35d950ef5a46045f5d6a9c71bdcf2 /lineset.c | |
parent | 526ce3a130732d4a2374a6e36a689d9e0cf5cc34 (diff) |
add undo support for box, visual, cut/paste
Diffstat (limited to 'lineset.c')
-rw-r--r-- | lineset.c | 38 |
1 files changed, 21 insertions, 17 deletions
@@ -127,19 +127,24 @@ void paste_region(int x1, int y1){ } void copy_lines_to_ring(int y1, int y2, int which){ - lineset_t *tmp; - int i, len, *idx; + int i, len, idx; + int offset; + lineset_t *tmp; if (y1 > y2){ y1 ^= y2; y2 ^= y1; y1 ^= y2; } - if (which == CUR) - idx = &undo_cur; + if (undo_cur > undo_lst) + undo_cur = undo_lst; + if (which == PRV_STATE){ /* adding a new previous state */ + undo_cur += 2; + idx = undo_cur; + } else - idx = &undo_lst; - if (*idx == undo_sz - 1){ + idx = undo_cur + 1; + if (idx >= undo_sz - 1){ undo_sz += 10; tmp = realloc(undo, undo_sz * sizeof(lineset_t)); if (tmp == NULL){ @@ -148,22 +153,21 @@ void copy_lines_to_ring(int y1, int y2, int which){ } undo = tmp; } - (*idx) ++; - ensure_num_lines(&(undo[*idx]), y2 - y1 + 1); + ensure_num_lines(&(undo[idx]), y2 - y1 + 1); for(i=y1; i<=y2; i++){ len = strlen(screen.l[i].s); - ensure_line_length(&(undo[*idx].l[i-y1]), len); - strcpy(undo[*idx].l[i-y1].s, screen.l[i].s); - undo[*idx].l[i-y1].n = i; - undo[*idx].l[i-y1].lst = screen.l[i].lst; + ensure_line_length(&(undo[idx].l[i-y1]), len); + strcpy(undo[idx].l[i-y1].s, screen.l[i].s); + undo[idx].l[i-y1].n = i; + undo[idx].l[i-y1].lst = screen.l[i].lst; } - undo[*idx].num = y2 - y1 + 1; - if (which == CUR) + undo[idx].num = y2 - y1 + 1; + if (which == PRV_STATE) undo_lst = undo_cur; #ifdef DEBUG - fprintf(stderr, "undo_ring: y1: %d y2: %d idx: %d\n", y1, y2, *idx); - for(i=0; i<undo[undo_cur].num; i++){ - fprintf(stderr, "UU: %d| %s\n", undo[*idx].l[i].n, undo[*idx].l[i].s); + fprintf(stderr, "undo_ring: y1: %d y2: %d idx: %d\n", y1, y2, idx); + for(i=0; i<undo[idx].num; i++){ + fprintf(stderr, "UU: %d| %s\n", undo[idx].l[i].n, undo[idx].l[i].s); } #endif } |