diff options
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 } |