From 9cbe6a640c7cc0cd9c2c029083c942aff980b0a3 Mon Sep 17 00:00:00 2001
From: Benno Schulenberg <bensberg@justemail.net>
Date: Thu, 5 May 2016 22:12:24 +0200
Subject: [PATCH] search: when polling the keyboard, consume all waiting
 keystrokes

When during searching we look at the keyboard, then don't look at
just the first keystroke, but check if there are more, and if so,
check each one until we find a Cancel -- or until all keystrokes
have been consumed and we can continue.

This fixes the first half of https://savannah.gnu.org/bugs/?47438.
---
 src/search.c | 12 ++++++++----
 1 file changed, 8 insertions(+), 4 deletions(-)

diff --git a/src/search.c b/src/search.c
index 24d6004e..910b3daa 100644
--- a/src/search.c
+++ b/src/search.c
@@ -292,10 +292,14 @@ int findnextstr(
 
 	    lastkbcheck = time(NULL);
 
-	    if (input && func_from_key(&input) == do_cancel) {
-		statusbar(_("Cancelled"));
-		disable_nodelay();
-		return -2;
+	    /* Consume all waiting keystrokes until a Cancel. */
+	    while (input) {
+		if (func_from_key(&input) == do_cancel) {
+		    statusbar(_("Cancelled"));
+		    disable_nodelay();
+		    return -2;
+		}
+		input = parse_kbinput(NULL);
 	    }
 
 	    if (++feedback > 0)
-- 
GitLab