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.
master
Benno Schulenberg 2020-08-10 11:42:09 +02:00
parent be20383240
commit 8e226a9f28
3 changed files with 18 additions and 8 deletions

View File

@ -200,9 +200,9 @@ void do_statusbar_verbatim_input(void)
bytes = get_verbatim_kbinput(bottomwin, &count); bytes = get_verbatim_kbinput(bottomwin, &count);
if (count > 0) if (0 < count && count < 999)
inject_into_answer(bytes, count); inject_into_answer(bytes, count);
else else if (count == 0)
beep(); beep();
free(bytes); free(bytes);

View File

@ -3016,15 +3016,17 @@ void do_verbatim_input(void)
/* When something valid was obtained, unsuppress cursor-position display, /* When something valid was obtained, unsuppress cursor-position display,
* insert the bytes into the edit buffer, and blank the status bar. */ * insert the bytes into the edit buffer, and blank the status bar. */
if (count > 0) { if (0 < count && count < 999) {
if (ISSET(CONSTANT_SHOW)) if (ISSET(CONSTANT_SHOW))
lastmessage = VACUUM; lastmessage = VACUUM;
inject(bytes, count); inject(bytes, count);
wipe_statusbar(); wipe_statusbar();
} else } else if (count == 0)
/* TRANSLATORS: An invalid verbatim Unicode code was typed. */ /* TRANSLATORS: An invalid verbatim Unicode code was typed. */
statusline(ALERT, _("Invalid code")); statusline(ALERT, _("Invalid code"));
else
wipe_statusbar();
free(bytes); free(bytes);
} }

View File

@ -1375,7 +1375,7 @@ int *parse_verbatim_kbinput(WINDOW *win, size_t *count)
#ifndef NANO_TINY #ifndef NANO_TINY
/* When the window was resized, abort and return nothing. */ /* When the window was resized, abort and return nothing. */
if (keycode == KEY_WINCH) { if (keycode == KEY_WINCH) {
*count = 0; *count = 999;
return NULL; return NULL;
} }
#endif #endif
@ -1397,6 +1397,12 @@ int *parse_verbatim_kbinput(WINDOW *win, size_t *count)
unicode = assemble_unicode(keycode); unicode = assemble_unicode(keycode);
} }
if (keycode == KEY_WINCH) {
*count = 999;
free(yield);
return NULL;
}
/* For an invalid digit, discard its possible continuation bytes. */ /* For an invalid digit, discard its possible continuation bytes. */
if (unicode == INVALID_DIGIT) if (unicode == INVALID_DIGIT)
while (key_buffer_len > 0 && 0x7F < *key_buffer && *key_buffer < 0xC0) 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); keypad(bottomwin, TRUE);
} }
for (size_t i = 0; i < *count; i++) if (*count < 999) {
bytes[i] = (char)input[i]; for (size_t i = 0; i < *count; i++)
bytes[*count] = '\0'; bytes[i] = (char)input[i];
bytes[*count] = '\0';
}
free(input); free(input);