From 387952894528eef3b124c843f47731ce3ab7ed25 Mon Sep 17 00:00:00 2001
From: David Lawrence Ramsey <pooka109@gmail.com>
Date: Tue, 29 Aug 2006 20:54:38 +0000
Subject: [PATCH] make sure that the statusbar cursor position is always
 properly reset when we get out of all statusbar prompts

git-svn-id: svn://svn.savannah.gnu.org/nano/trunk/nano@3865 35c25a1d-7b9e-4130-9fde-d3aeb78583b8
---
 ChangeLog    | 5 +++++
 src/files.c  | 9 ++-------
 src/nano.c   | 8 ++++----
 src/prompt.c | 7 +++++--
 4 files changed, 16 insertions(+), 13 deletions(-)

diff --git a/ChangeLog b/ChangeLog
index 09c5cb82..75128b56 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,4 +1,9 @@
 CVS code -
+- General:
+	- Make sure that the statusbar cursor position is always
+	  properly reset when we get out of all statusbar prompts.
+	  Changes to do_insertfile(), do_writeout(),
+	  handle_sigwinch(), main(), and do_prompt_abort(). (DLR)
 
 GNU nano 1.9.99pre1 - 2006.08.29
 - General:
diff --git a/src/files.c b/src/files.c
index a9190e79..09f9fb59 100644
--- a/src/files.c
+++ b/src/files.c
@@ -766,13 +766,11 @@ void do_insertfile(
 		if (tmp == NULL)
 		    continue;
 
+		/* We have a file now.  Indicate this. */
 		free(answer);
 		answer = tmp;
 
-		/* We have a file now.  Indicate this and get out of the
-		 * statusbar prompt cleanly. */
 		i = 0;
-		do_prompt_abort();
 	    }
 #endif
 
@@ -1825,12 +1823,9 @@ int do_writeout(bool exiting)
 		if (tmp == NULL)
 		    continue;
 
+		/* We have a file now.  Indicate this. */
 		free(answer);
 		answer = tmp;
-
-		/* We have a file now.  Get out of the statusbar prompt
-		 * cleanly. */
-		do_prompt_abort();
 	    } else
 #endif /* !DISABLE_BROWSER */
 #ifndef NANO_TINY
diff --git a/src/nano.c b/src/nano.c
index 7ce83123..e2a13365 100644
--- a/src/nano.c
+++ b/src/nano.c
@@ -1088,10 +1088,6 @@ RETSIGTYPE handle_sigwinch(int signal)
     COLS = win.ws_col;
     LINES = win.ws_row;
 
-    /* Just in case we're in the statusbar prompt, reset the statusbar
-     * cursor position. */
-     do_prompt_abort();
-
     /* If we've partitioned the filestruct, unpartition it now. */
     if (filepart != NULL)
 	unpartition_filestruct(&filepart);
@@ -2252,6 +2248,10 @@ int main(int argc, char **argv)
 	/* Read in and interpret characters. */
 	do_input(&meta_key, &func_key, &s_or_t, &ran_func, &finished,
 		TRUE);
+
+	 /* Just in case we were in the statusbar prompt, reset the
+	  * statusbar cursor position. */
+	 do_prompt_abort();
     }
 
     /* We should never get here. */
diff --git a/src/prompt.c b/src/prompt.c
index 626ca252..bccc5d16 100644
--- a/src/prompt.c
+++ b/src/prompt.c
@@ -1247,10 +1247,13 @@ int do_prompt(bool allow_tabs,
 }
 
 /* This function forces a reset of the statusbar cursor position.  It
- * should only be called after do_prompt(), and is only needed if we
- * leave the prompt via something other than Cancel or Enter. */
+ * should be called when we get out of all statusbar prompts. */
 void do_prompt_abort(void)
 {
+    /* Uninitialize the old cursor position in answer. */
+    old_statusbar_x = (size_t)-1;
+    old_pww = (size_t)-1;
+
     reset_statusbar_x = TRUE;
 }
 
-- 
GitLab