diff --git a/ChangeLog b/ChangeLog
index 35f07f739dd757417f8dfe69f9807cfd2210e39f..3af2dd5df693a03a762ab75bf96bdad973d47145 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -75,6 +75,9 @@ CVS code -
 	  contains invalid multibyte characters interpreted as normal
 	  characters.  Changes to mbstrncasecmp(), mbstrcasestr(),
 	  mbrevstrcasestr(), findnextstr(), and do_replace_loop(). (DLR)
+	- Make sure that the current position in the history list is
+	  properly set to the bottom if we cancel out of the prompt.
+	  New function history_reset(); changes to nanogetstr(). (DLR)
 - files.c:
   open_file()
 	- Assert that filename isn't NULL, and don't do anything special
diff --git a/src/proto.h b/src/proto.h
index e8a5c609d2270104f847b61a1e020a12228cd8fe..a2d7e5162a789bcda21c322be09dfa6119829f99 100644
--- a/src/proto.h
+++ b/src/proto.h
@@ -517,6 +517,7 @@ void do_find_bracket(void);
 bool history_has_changed(void);
 #endif
 void history_init(void);
+void history_reset(const filestruct *h);
 filestruct *find_history(filestruct *h_start, filestruct *h_end, const
 	char *s, size_t len);
 void update_history(filestruct **h, const char *s);
diff --git a/src/search.c b/src/search.c
index 034d3de2953063440115f2c663468e6d31f3713d..0a527a1b568871464c03dcd8f16a64797515c597 100644
--- a/src/search.c
+++ b/src/search.c
@@ -1185,6 +1185,15 @@ void history_init(void)
     replacebot = replace_history;
 }
 
+/* Set the current position in the history list h to the bottom. */
+void history_reset(const filestruct *h)
+{
+    if (h == search_history)
+	search_history = searchbot;
+    else if (h == replace_history)
+	replace_history = replacebot;
+}
+
 /* Return the first node containing the first len characters of the
  * string s in the history list, starting at h_start and ending at
  * h_end, or NULL if there isn't one. */
diff --git a/src/winio.c b/src/winio.c
index da0d89d3b9198ba3615569de2ea2c498bd6bc62d..d9f9c574580753c352b8fde5408f1a817a99e5c2 100644
--- a/src/winio.c
+++ b/src/winio.c
@@ -2642,9 +2642,14 @@ int nanogetstr(bool allow_tabs, const char *buf, const char *curranswer,
     }
 
 #ifndef NANO_SMALL
-    /* Free magichistory if we need to. */
-    if (magichistory != NULL)
-	free(magichistory);
+    /* Set the current position in the history list to the bottom and
+     * free magichistory, if we need to. */
+    if (history_list != NULL) {
+	history_reset(*history_list);
+
+	if (magichistory != NULL)
+	    free(magichistory);
+    }
 #endif
 
     /* We finished putting in an answer or ran a normal shortcut's