From 526ce3a130732d4a2374a6e36a689d9e0cf5cc34 Mon Sep 17 00:00:00 2001 From: KatolaZ Date: Wed, 31 Jul 2019 00:10:35 +0100 Subject: preliminary support for undo --- lineset.c | 43 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 43 insertions(+) (limited to 'lineset.c') diff --git a/lineset.c b/lineset.c index f672798..40fe3f0 100644 --- a/lineset.c +++ b/lineset.c @@ -58,6 +58,7 @@ void ensure_num_lines(lineset_t *ls, int n){ } } + void dump_lines(lineset_t ls, FILE *f){ int i; for (i=0; i y2){ + y1 ^= y2; + y2 ^= y1; + y1 ^= y2; + } + if (which == CUR) + idx = &undo_cur; + else + idx = &undo_lst; + if (*idx == undo_sz - 1){ + undo_sz += 10; + tmp = realloc(undo, undo_sz * sizeof(lineset_t)); + if (tmp == NULL){ + fprintf(stderr, "Error allocating undo buffer"); + exit(1); + } + undo = tmp; + } + (*idx) ++; + 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; + } + undo[*idx].num = y2 - y1 + 1; + if (which == CUR) + undo_lst = undo_cur; +#ifdef DEBUG + fprintf(stderr, "undo_ring: y1: %d y2: %d idx: %d\n", y1, y2, *idx); + for(i=0; i