summaryrefslogtreecommitdiff
path: root/draw.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 /draw.c
parent526ce3a130732d4a2374a6e36a689d9e0cf5cc34 (diff)
add undo support for box, visual, cut/paste
Diffstat (limited to 'draw.c')
-rw-r--r--draw.c32
1 files changed, 18 insertions, 14 deletions
diff --git a/draw.c b/draw.c
index e3bdbce..e4c3250 100644
--- a/draw.c
+++ b/draw.c
@@ -112,7 +112,7 @@ void draw_box(int x1, int y1, int fix){
if (fix == FIX){
f = set_xy;
- copy_lines_to_ring(ymin, ymax, CUR);
+ copy_lines_to_ring(ymin, ymax, PRV_STATE);
}
else
f = draw_xy;
@@ -130,7 +130,7 @@ void draw_box(int x1, int y1, int fix){
f(xmax, ymin, corner);
f(xmax, ymax, corner);
if (fix == FIX)
- copy_lines_to_ring(ymin, ymax, LST);
+ copy_lines_to_ring(ymin, ymax, NEW_STATE);
show_cursor();
}
@@ -316,10 +316,10 @@ void visual_box(FILE *fc){
case 'x':/* erase */
if (c == 'x')
yank_region(MIN(orig_x,x), MIN(orig_y,y), MAX(orig_x, x), MAX(orig_y, y));
- copy_lines_to_ring(MIN(orig_y, y), MAX(orig_y, y), CUR);
+ copy_lines_to_ring(MIN(orig_y, y), MAX(orig_y, y), PRV_STATE);
erase_box(orig_x, orig_y, f);
erase_blank_lines(MIN(y,orig_y), MAX(y, orig_y));
- copy_lines_to_ring(MIN(orig_y, y), MAX(orig_y, y), LST);
+ copy_lines_to_ring(MIN(orig_y, y), MAX(orig_y, y), NEW_STATE);
modified = 1;
goto vis_exit;
@@ -345,9 +345,9 @@ void paste(){
int y2;
y2 = y + cutbuf.num - 1;
- copy_lines_to_ring(y, y2, CUR);
+ copy_lines_to_ring(y, y2, PRV_STATE);
paste_region(x, y);
- copy_lines_to_ring(y, y2, LST);
+ copy_lines_to_ring(y, y2, NEW_STATE);
redraw();
}
@@ -356,28 +356,32 @@ void put_lines(lineset_t *u){
for (i=0; i< u->num; i++){
n = u->l[i].n;
- ensure_line_length(&(screen.l[i]), u->l[i].lst);
+ ensure_line_length(&(screen.l[i]), strlen(u->l[i].s));
strcpy(screen.l[n].s, u->l[i].s);
- screen.l[n].lst = u->l[i].lst;
+ screen.l[n].lst = strlen(u->l[i].s)-1;
}
}
void undo_change(){
if (undo_cur >= 0){
+ if (undo_cur > undo_lst)
+ undo_cur = undo_lst;
put_lines(& (undo[undo_cur]));
- undo_cur --;
+ undo_cur -= 2;
+ modified = 1;
}
redraw();
- modified = 1;
}
void redo_change(){
- if (undo_cur < undo_lst){
- undo_cur ++;
- put_lines(& (undo[undo_cur]));
+ if (undo_cur <= undo_lst-2){
+ if (undo_cur > 0)
+ put_lines(& (undo[undo_cur+1]));
+ undo_cur +=2;
+ put_lines(& (undo[undo_cur+1]));
+ modified = 1;
}
redraw();
- modified = 1;
}