From 08485aacd8d561f2650175b7a16211262396b2ce Mon Sep 17 00:00:00 2001
From: KatolaZ <katolaz@freaknet.org>
Date: Thu, 1 Aug 2019 11:26:12 +0100
Subject: add undo in erase mode

---
 draw.c | 16 ++++++++++++++--
 1 file changed, 14 insertions(+), 2 deletions(-)

(limited to 'draw.c')

diff --git a/draw.c b/draw.c
index bc6657d..ae90458 100644
--- a/draw.c
+++ b/draw.c
@@ -168,7 +168,6 @@ update_box:
 
 void draw_arrow(int x, int y, char *a, int a_len, int fix){
 
-	/* FIXME: copy affected lines to undo */
 	int i, j, cur_dir;
 	char line;
 	void (*f)(int, int, char);
@@ -285,13 +284,24 @@ void erase(FILE *fc){
 	/*FIXME: add affected lines to undo */
 	char c;
 	int orig_x = x, orig_y = y;
+	char first = 1, opened = 0;
 	status_bar();
 	show_cursor();
-	invalidate_undo();
 	while((c=fgetc(fc))!=EOF && c!=27 && c!= 'x' && c != '\n'){
 		if (!move_around(c, fc)) continue;
 		check_bound();
+		if (first || 
+		    (y != orig_y && ! opened) ||
+		    (y == orig_y && x != orig_x && !opened) ){
+			copy_lines_to_ring(MIN(y, orig_y), MAX(y, orig_y), PRV_STATE);
+			first = 0;
+			opened = 1;
+		}
 		do_erase(orig_x, orig_y);
+		if (y != orig_y && opened){
+			copy_lines_to_ring(MIN(y, orig_y), MAX(y, orig_y), NEW_STATE);
+			opened = 0;
+		}
 		step = 1;
 		modified = 1;
 		orig_x = x;
@@ -300,6 +310,8 @@ void erase(FILE *fc){
 		status_bar();
 		show_cursor();
 	}
+	if (opened)
+		copy_lines_to_ring(y, y, NEW_STATE);
 	mode = MOVE;
 }
 
-- 
cgit v1.2.3