nano

nano with my custom patches
git clone git://bsandro.tech/nano
Log | Files | Refs | README | LICENSE

commit 8e226a9f28ec7ee063a22309f1b1de80562d3565
parent be203832408da8076da555cab8e9f4690a6da2ff
Author: Benno Schulenberg <bensberg@telfort.nl>
Date:   Mon, 10 Aug 2020 11:42:09 +0200

verbatim: do not report "Invalid code" when the terminal is resized

During verbatim input at most four integers are produced (the longest
possible unicode sequence), so use the value 999 to indicate a special
condition (a screen resize) that should not enter anything into the
buffer AND should not produce any error message or beep.

This fixes https://savannah.gnu.org/bugs/?58923.

Bug existed since version 5.0, commit 5899181a.

Diffstat:
Msrc/prompt.c | 4++--
Msrc/text.c | 6++++--
Msrc/winio.c | 16++++++++++++----
3 files changed, 18 insertions(+), 8 deletions(-)

diff --git a/src/prompt.c b/src/prompt.c @@ -200,9 +200,9 @@ void do_statusbar_verbatim_input(void) bytes = get_verbatim_kbinput(bottomwin, &count); - if (count > 0) + if (0 < count && count < 999) inject_into_answer(bytes, count); - else + else if (count == 0) beep(); free(bytes); diff --git a/src/text.c b/src/text.c @@ -3016,15 +3016,17 @@ void do_verbatim_input(void) /* When something valid was obtained, unsuppress cursor-position display, * insert the bytes into the edit buffer, and blank the status bar. */ - if (count > 0) { + if (0 < count && count < 999) { if (ISSET(CONSTANT_SHOW)) lastmessage = VACUUM; inject(bytes, count); wipe_statusbar(); - } else + } else if (count == 0) /* TRANSLATORS: An invalid verbatim Unicode code was typed. */ statusline(ALERT, _("Invalid code")); + else + wipe_statusbar(); free(bytes); } diff --git a/src/winio.c b/src/winio.c @@ -1375,7 +1375,7 @@ int *parse_verbatim_kbinput(WINDOW *win, size_t *count) #ifndef NANO_TINY /* When the window was resized, abort and return nothing. */ if (keycode == KEY_WINCH) { - *count = 0; + *count = 999; return NULL; } #endif @@ -1397,6 +1397,12 @@ int *parse_verbatim_kbinput(WINDOW *win, size_t *count) unicode = assemble_unicode(keycode); } + if (keycode == KEY_WINCH) { + *count = 999; + free(yield); + return NULL; + } + /* For an invalid digit, discard its possible continuation bytes. */ if (unicode == INVALID_DIGIT) while (key_buffer_len > 0 && 0x7F < *key_buffer && *key_buffer < 0xC0) @@ -1480,9 +1486,11 @@ char *get_verbatim_kbinput(WINDOW *win, size_t *count) keypad(bottomwin, TRUE); } - for (size_t i = 0; i < *count; i++) - bytes[i] = (char)input[i]; - bytes[*count] = '\0'; + if (*count < 999) { + for (size_t i = 0; i < *count; i++) + bytes[i] = (char)input[i]; + bytes[*count] = '\0'; + } free(input);