From c918c6563b24ebbd47aae5fb12eb2d25735b33c5 Mon Sep 17 00:00:00 2001
From: Benno Schulenberg <bensberg@justemail.net>
Date: Thu, 5 May 2016 21:44:45 +0200
Subject: [PATCH] input: properly restore waiting mode, or retain non-waiting
 mode

Cancelling a search should restore waiting mode for the keyboard,
just like at the other exit points of the search routine.

And when the input routine has read in multiple keystrokes, it
should not blindly switch back to waiting mode, but only when
that mode was on before.

This fixes the second half of https://savannah.gnu.org/bugs/?47438.
---
 src/search.c | 1 +
 src/winio.c  | 5 +++--
 2 files changed, 4 insertions(+), 2 deletions(-)

diff --git a/src/search.c b/src/search.c
index a7f19a7f..24d6004e 100644
--- a/src/search.c
+++ b/src/search.c
@@ -294,6 +294,7 @@ int findnextstr(
 
 	    if (input && func_from_key(&input) == do_cancel) {
 		statusbar(_("Cancelled"));
+		disable_nodelay();
 		return -2;
 	    }
 
diff --git a/src/winio.c b/src/winio.c
index 5260a580..549a087f 100644
--- a/src/winio.c
+++ b/src/winio.c
@@ -180,8 +180,9 @@ void get_key_buffer(WINDOW *win)
 	key_buffer[key_buffer_len - 1] = input;
     }
 
-    /* Switch back to waiting mode for input. */
-    nodelay(win, FALSE);
+    /* Restore waiting mode if it was on. */
+    if (!nodelay_mode)
+	nodelay(win, FALSE);
 
 #ifdef DEBUG
     {
-- 
GitLab