[prev in list] [next in list] [prev in thread] [next in thread] 

List:       nano-devel
Subject:    [Nano-devel] [PATCH] undo: unset the Modified state when the very first edit is undone
From:       Benno Schulenberg <bensberg () telfort ! nl>
Date:       2017-11-25 19:29:51
Message-ID: 20171125192951.30181-1-bensberg () telfort ! nl
[Download RAW message or body]

This also means that no question needs to be asked when exiting.

This fixes https://savannah.gnu.org/bugs/?52504.
Reported-by: Peter Passchier <peter@passchier.net>
---
 src/files.c | 1 +
 src/nano.h  | 3 +++
 src/text.c  | 9 ++++++++-
 3 files changed, 12 insertions(+), 1 deletion(-)

diff --git a/src/files.c b/src/files.c
index 382ccb19..36c09caa 100644
--- a/src/files.c
+++ b/src/files.c
@@ -100,6 +100,7 @@ void make_new_buffer(void)
     openfile->undotop = NULL;
     openfile->current_undo = NULL;
     openfile->last_action = OTHER;
+    openfile->pristine = TRUE;
 
     openfile->current_stat = NULL;
     openfile->lock_filename = NULL;
diff --git a/src/nano.h b/src/nano.h
index 0f7e0f6e..9ab9281f 100644
--- a/src/nano.h
+++ b/src/nano.h
@@ -396,6 +396,9 @@ typedef struct openfilestruct {
 	/* The current (i.e. next) level of undo. */
     undo_type last_action;
 	/* The type of the last action the user performed. */
+    bool pristine;
+	/* Whether the undo stack still contains the first edit -- it won't
+	 * when a justification or spell check discarded the undo stack. */
     char *lock_filename;
 	/* The path of the lockfile, if we created one. */
 #endif
diff --git a/src/text.c b/src/text.c
index 6b9399ef..68cd5991 100644
--- a/src/text.c
+++ b/src/text.c
@@ -865,7 +865,13 @@ void do_undo(void)
     openfile->placewewant = xplustabs();
 
     openfile->totsize = u->wassize;
-    set_modified();
+
+    /* If *everything* was undone, then unset the "Modified" marker. */
+    if (openfile->current_undo == NULL && openfile->pristine) {
+	openfile->modified = FALSE;
+	titlebar(NULL);
+    } else
+	set_modified();
 }
 
 /* Redo the last thing(s) we undid. */
@@ -1200,6 +1206,7 @@ void discard_until(const undo *thisitem, openfilestruct *thefile)
 	}
 	free(dropit);
 	dropit = thefile->undotop;
+	thefile->pristine = FALSE;
     }
 
     /* Adjust the pointer to the top of the undo stack. */
-- 
2.14.3


_______________________________________________
Nano-devel mailing list
Nano-devel@gnu.org
https://lists.gnu.org/mailman/listinfo/nano-devel
[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic