From 47fcfe5d7825d7ce9db3bdedcdc0dceb70456eb7 Mon Sep 17 00:00:00 2001
From: Chris Allegretta <chrisa@asty.org>
Date: Sun, 26 Jan 2003 21:01:16 +0000
Subject: [PATCH] - Fix cursor position being saved when escaping out of
 nanogetstr with keys like ^Y and ^V.  New arg resetpos to nanogetstr(), added
 static int resetpos in statusq() (bug found by DLR)

git-svn-id: svn://svn.savannah.gnu.org/nano/trunk/nano@1399 35c25a1d-7b9e-4130-9fde-d3aeb78583b8
---
 ChangeLog |  4 ++++
 proto.h   |  2 +-
 winio.c   | 12 +++++++++---
 3 files changed, 14 insertions(+), 4 deletions(-)

diff --git a/ChangeLog b/ChangeLog
index 85a40ab7..3e76ba29 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -8,6 +8,10 @@ CVS Code -
 	- Fix subexpression replacement to work consistently.
 	  Affects search.c:replace_regexp() and 
 	  utils.c:strstrwrapper() (David Benbennick).
+	- Fix cursor position being saved when escaping out 
+	  of nanogetstr with keys like ^Y and ^V.  New arg
+	  resetpos to nanogetstr(), added static int
+	  resetpos in statusq() (bug found by DLR).
 - cut.c:
   do_cut_text()
 	- Fix incorrect cursor location when cutting long lines
diff --git a/proto.h b/proto.h
index f981d98e..645e8226 100644
--- a/proto.h
+++ b/proto.h
@@ -425,7 +425,7 @@ int nanogetstr(int allowtabs, const char *buf, const char *def,
 #ifndef DISABLE_TABCOMP
 		, int *list
 #endif
-		);
+		, int resetpos);
 void set_modified(void);
 void titlebar(const char *path);
 void bottombars(const shortcut *s);
diff --git a/winio.c b/winio.c
index 3ed47626..1f221bd9 100644
--- a/winio.c
+++ b/winio.c
@@ -194,7 +194,7 @@ int nanogetstr(int allowtabs, const char *buf, const char *def,
 #ifndef DISABLE_TABCOMP
 		, int *list
 #endif
-		)
+		, int resetpos)
 {
     int kbinput;
     static int x = -1;
@@ -218,7 +218,7 @@ int nanogetstr(int allowtabs, const char *buf, const char *def,
        it would be past the end of the string as it is.  Otherwise,
        leave it alone.  This is so the cursor position stays at the same
        place if a prompt-changing toggle is pressed. */
-    if (x == -1 || x > xend)
+    if (x == -1 || x > xend || resetpos)
 	x = xend;
 
     answer = (char *)nrealloc(answer, xend + 1);
@@ -1175,6 +1175,8 @@ int statusq(int tabs, const shortcut *s, const char *def,
 #ifndef DISABLE_TABCOMP
     int list = 0;
 #endif
+    static int resetpos = 0;	/* Do we need to scrap the cursor position 
+				   on the statusbar? */
 
     bottombars(s);
 
@@ -1191,18 +1193,22 @@ int statusq(int tabs, const shortcut *s, const char *def,
 #ifndef DISABLE_TABCOMP
 		, &list
 #endif
-		);
+		, resetpos);
     free(foo);
+    resetpos = 0;
 
     switch (ret) {
     case NANO_FIRSTLINE_KEY:
 	do_first_line();
+	resetpos = 1;
 	break;
     case NANO_LASTLINE_KEY:
 	do_last_line();
+	resetpos = 1;
 	break;
     case NANO_CANCEL_KEY:
 	ret = -1;
+	resetpos = 1;
 	break;
     default:
 	blank_statusbar();
-- 
GitLab