nano-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Nano-devel] [PATCH] text: fix the Modified state not being set correctl


From: Benno Schulenberg
Subject: [Nano-devel] [PATCH] text: fix the Modified state not being set correctly by undo/redo
Date: Mon, 18 Dec 2017 20:37:07 +0100

This is a partial fix, because write_file() also gets called when
writing out a marked region.  A correct fix will require some other
changes first.

Reported-by: Liu Hao <address@hidden>
Original-idea-by: Brand Huntsman <address@hidden>
---
 src/files.c |  3 +++
 src/nano.h  |  2 ++
 src/text.c  | 11 +++++++++--
 3 files changed, 14 insertions(+), 2 deletions(-)

diff --git a/src/files.c b/src/files.c
index cdd9f2cd..dea8c060 100644
--- a/src/files.c
+++ b/src/files.c
@@ -99,6 +99,7 @@ void make_new_buffer(void)
 
     openfile->undotop = NULL;
     openfile->current_undo = NULL;
+    openfile->last_saved = NULL;
     openfile->last_action = OTHER;
     openfile->pristine = TRUE;
 
@@ -1958,6 +1959,8 @@ bool write_file(const char *name, FILE *f_open, bool tmp,
        statusline(HUSH, P_("Wrote %zu line", "Wrote %zu lines",
                        lineswritten), lineswritten);
        openfile->modified = FALSE;
+       openfile->last_saved = openfile->current_undo;
+       openfile->last_action = OTHER;
        titlebar(NULL);
     }
 
diff --git a/src/nano.h b/src/nano.h
index 7e6d8f81..c84b542e 100644
--- a/src/nano.h
+++ b/src/nano.h
@@ -394,6 +394,8 @@ typedef struct openfilestruct {
        /* The top of the undo list. */
     undo *current_undo;
        /* The current (i.e. next) level of undo. */
+    undo *last_saved;
+       /* The undo item at which the file was last saved. */
     undo_type last_action;
        /* The type of the last action the user performed. */
     bool pristine;
diff --git a/src/text.c b/src/text.c
index a01bcc86..99a5fb8b 100644
--- a/src/text.c
+++ b/src/text.c
@@ -869,7 +869,7 @@ void do_undo(void)
     openfile->totsize = u->wassize;
 
     /* If *everything* was undone, then unset the "Modified" marker. */
-    if (openfile->current_undo == NULL && openfile->pristine) {
+    if (openfile->current_undo == openfile->last_saved && openfile->pristine) {
        openfile->modified = FALSE;
        titlebar(NULL);
     } else
@@ -1028,7 +1028,14 @@ void do_redo(void)
     openfile->placewewant = xplustabs();
 
     openfile->totsize = u->newsize;
-    set_modified();
+
+    /* If we are at the point where the file was last saved, then
+     * unset the "Modified" marker. */
+    if (openfile->current_undo == openfile->last_saved) {
+       openfile->modified = FALSE;
+       titlebar(NULL);
+    } else
+       set_modified();
 }
 #endif /* !NANO_TINY */
 
-- 
2.14.3




reply via email to

[Prev in Thread] Current Thread [Next in Thread]