nano-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Nano-devel] [PATCH] input: treat Ctrl+Alt+key different from Esc follow


From: Benno Schulenberg
Subject: [Nano-devel] [PATCH] input: treat Ctrl+Alt+key different from Esc followed by Ctrl+key
Date: Mon, 11 Jul 2016 16:18:51 +0200

When the user changes her mind after having pressed Esc, she cannot
unpress Esc, so do that for her by ignoring the escape code when
the subsequent keycode is outside of the normal printable range.

This restores the behavior from before nano-2.3.5 -- except that
Ctrl+Alt+key continues to report an unbound key.

This fixes https://savannah.gnu.org/bugs/?48459.
---
 src/nano.c  | 5 +++++
 src/winio.c | 6 +++++-
 2 files changed, 10 insertions(+), 1 deletion(-)

diff --git a/src/nano.c b/src/nano.c
index 9484f01..d00f7e6 100644
--- a/src/nano.c
+++ b/src/nano.c
@@ -2527,6 +2527,11 @@ int main(int argc, char **argv)
        controlright = key_defined(keyvalue);
 #endif
 
+#ifndef USE_SLANG
+    /* Tell ncurses to pass the Esc key quickly. */
+    set_escdelay(50);
+#endif
+
 #ifdef DEBUG
     fprintf(stderr, "Main: open file\n");
 #endif
diff --git a/src/winio.c b/src/winio.c
index d26cea0..ccf9520 100644
--- a/src/winio.c
+++ b/src/winio.c
@@ -40,6 +40,8 @@ static int *key_buffer = NULL;
         * haven't handled yet at a given point. */
 static size_t key_buffer_len = 0;
        /* The length of the keystroke buffer. */
+static bool solitary = FALSE;
+       /* Whether an Esc arrived by itself, or as leader of a group. */
 static int statusblank = 0;
        /* The number of keystrokes left before we blank the statusbar. */
 static bool suppress_cursorpos = FALSE;
@@ -362,6 +364,7 @@ int parse_kbinput(WINDOW *win)
            /* If there are four consecutive escapes, discard three of them. */
            if (escapes > 3)
                escapes = 1;
+           solitary = (escapes == 1 && get_key_buffer_len() == 0);
            /* Wait for more input. */
            break;
        default:
@@ -376,7 +379,8 @@ int parse_kbinput(WINDOW *win)
                    if (get_key_buffer_len() == 0 || key_buffer[0] == 0x1b) {
                        /* One escape followed by a single non-escape:
                         * meta key sequence mode. */
-                       meta_key = TRUE;
+                       if (!solitary || (*kbinput >= 0x20 && *kbinput < 0x7F))
+                           meta_key = TRUE;
                        retval = tolower(*kbinput);
                    } else
                        /* One escape followed by a non-escape, and there
-- 
2.8.4




reply via email to

[Prev in Thread] Current Thread [Next in Thread]