summaryrefslogtreecommitdiff
path: root/lineset.c
diff options
context:
space:
mode:
authorKatolaZ <katolaz@freaknet.org>2019-07-31 11:19:55 +0100
committerKatolaZ <katolaz@freaknet.org>2019-07-31 11:19:55 +0100
commitf3100ddd486d6f39b0c97c9c492bb6020bf3caf1 (patch)
tree729407153bc35d950ef5a46045f5d6a9c71bdcf2 /lineset.c
parent526ce3a130732d4a2374a6e36a689d9e0cf5cc34 (diff)
add undo support for box, visual, cut/paste
Diffstat (limited to 'lineset.c')
-rw-r--r--lineset.c38
1 files changed, 21 insertions, 17 deletions
diff --git a/lineset.c b/lineset.c
index 40fe3f0..75ae1d3 100644
--- a/lineset.c
+++ b/lineset.c
@@ -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
}