From f3100ddd486d6f39b0c97c9c492bb6020bf3caf1 Mon Sep 17 00:00:00 2001 From: KatolaZ Date: Wed, 31 Jul 2019 11:19:55 +0100 Subject: add undo support for box, visual, cut/paste --- lineset.c | 38 +++++++++++++++++++++----------------- 1 file changed, 21 insertions(+), 17 deletions(-) (limited to 'lineset.c') 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