Commit a44ca78a authored by David Lawrence Ramsey's avatar David Lawrence Ramsey
Browse files

in parse_kbinput(), properly handle combined meta and escape sequences,

so that e.g. Meta-+ will work properly when the + is on the numeric
keypad and NumLock is off


git-svn-id: svn://svn.savannah.gnu.org/nano/trunk/nano@3805 35c25a1d-7b9e-4130-9fde-d3aeb78583b8
parent 006fc233
No related merge requests found
Showing with 99 additions and 68 deletions
+99 -68
...@@ -131,6 +131,10 @@ CVS code - ...@@ -131,6 +131,10 @@ CVS code -
- Remove the marking of the file as modified, as do_insertfile() - Remove the marking of the file as modified, as do_insertfile()
now handles that. (DLR) now handles that. (DLR)
- winio.c: - winio.c:
parse_kbinput()
- Properly handle combined meta and escape sequences, so that
e.g. Meta-+ will work properly when the + is on the numeric
keypad and NumLock is off. (DLR)
display_string() display_string()
- Properly handle buf[start_index]'s being a null terminator. - Properly handle buf[start_index]'s being a null terminator.
(DLR) (DLR)
......
...@@ -505,19 +505,20 @@ int parse_kbinput(WINDOW *win, bool *meta_key, bool *func_key) ...@@ -505,19 +505,20 @@ int parse_kbinput(WINDOW *win, bool *meta_key, bool *func_key)
} }
break; break;
case 1: case 1:
/* One escape followed by a non-escape: escape /* Reset the escape counter. */
* sequence mode. Reset the escape counter. If
* there aren't any other keys waiting, we have a
* meta key sequence, so set meta_key to TRUE and
* save the lowercase version of the non-escape
* character as the result. If there are other keys
* waiting, we have a true escape sequence, so
* interpret it. */
escapes = 0; escapes = 0;
if (get_key_buffer_len() == 0) { if (get_key_buffer_len() == 0) {
/* One escape followed by a non-escape, and
* there aren't any other keys waiting: meta key
* sequence mode. Set meta_key to TRUE and save
* the lowercase version of the non-escape
* character as the result. */
*meta_key = TRUE; *meta_key = TRUE;
retval = tolower(*kbinput); retval = tolower(*kbinput);
} else { } else {
/* One escape followed by a non-escape, and
* there are other keys waiting: escape sequence
* mode. Interpret the escape sequence. */
bool ignore_seq; bool ignore_seq;
retval = parse_escape_seq_kbinput(*kbinput, retval = parse_escape_seq_kbinput(*kbinput,
...@@ -533,18 +534,21 @@ int parse_kbinput(WINDOW *win, bool *meta_key, bool *func_key) ...@@ -533,18 +534,21 @@ int parse_kbinput(WINDOW *win, bool *meta_key, bool *func_key)
} }
break; break;
case 2: case 2:
/* Two escapes followed by one or more decimal if (get_key_buffer_len() == 0) {
* digits: byte sequence mode. If the byte
* sequence's range is limited to 2XX (the first
* digit is in the '0' to '2' range and it's the
* first digit, or it's in the '0' to '9' range and
* it's not the first digit), increment the byte
* sequence counter and interpret the digit. If the
* byte sequence's range is not limited to 2XX, fall
* through. */
if (('0' <= *kbinput && *kbinput <= '2' && if (('0' <= *kbinput && *kbinput <= '2' &&
byte_digits == 0) || ('0' <= *kbinput && byte_digits == 0) || ('0' <= *kbinput &&
*kbinput <= '9' && byte_digits > 0)) { *kbinput <= '9' && byte_digits > 0)) {
/* Two escapes followed by one or more
* decimal digits, and there aren't any
* other keys waiting: byte sequence mode.
* If the byte sequence's range is limited
* to 2XX (the first digit is in the '0' to
* '2' range and it's the first digit, or
* it's in the '0' to '9' range and it's not
* the first digit), increment the byte
* sequence counter and interpret the digit.
* If the byte sequence's range is not
* limited to 2XX, fall through. */
int byte; int byte;
byte_digits++; byte_digits++;
...@@ -555,14 +559,15 @@ int parse_kbinput(WINDOW *win, bool *meta_key, bool *func_key) ...@@ -555,14 +559,15 @@ int parse_kbinput(WINDOW *win, bool *meta_key, bool *func_key)
int byte_mb_len, *seq, i; int byte_mb_len, *seq, i;
/* If we've read in a complete byte /* If we've read in a complete byte
* sequence, reset the byte sequence counter * sequence, reset the escape counter
* and the escape counter, and put back the * and the byte sequence counter, and
* corresponding byte value. */ * put back the corresponding byte
byte_digits = 0; * value. */
escapes = 0; escapes = 0;
byte_digits = 0;
/* Put back the multibyte equivalent of the /* Put back the multibyte equivalent of
* byte value. */ * the byte value. */
byte_mb = make_mbchar((long)byte, byte_mb = make_mbchar((long)byte,
&byte_mb_len); &byte_mb_len);
...@@ -583,22 +588,44 @@ int parse_kbinput(WINDOW *win, bool *meta_key, bool *func_key) ...@@ -583,22 +588,44 @@ int parse_kbinput(WINDOW *win, bool *meta_key, bool *func_key)
if (byte_digits == 0) if (byte_digits == 0)
/* Two escapes followed by a non-decimal /* Two escapes followed by a non-decimal
* digit or a decimal digit that would * digit or a decimal digit that would
* create a byte sequence greater than 2XX, * create a byte sequence greater than
* and we're not in the middle of a byte * 2XX, we're not in the middle of a
* sequence: control character sequence * byte sequence, and there aren't any
* mode. Interpret the control sequence and * other keys waiting: control character
* save the corresponding control character * sequence mode. Interpret the control
* as the result. */ * sequence and save the corresponding
* control character as the result. */
retval = get_control_kbinput(*kbinput); retval = get_control_kbinput(*kbinput);
else { else {
/* If we're in the middle of a byte /* If we're in the middle of a byte
* sequence, reset the byte sequence counter * sequence, reset the byte sequence
* and save the character we got as the * counter and save the character we got
* result. */ * as the result. */
byte_digits = 0; byte_digits = 0;
retval = *kbinput; retval = *kbinput;
} }
} }
} else {
/* Two escapes followed by a non-escape, and
* there are other keys waiting: combined meta
* and escape sequence mode. Reset the escape
* counter, set meta_key to TRUE, and interpret
* the escape sequence. */
bool ignore_seq;
escapes = 0;
*meta_key = TRUE;
retval = parse_escape_seq_kbinput(*kbinput,
&ignore_seq);
/* If the escape sequence is unrecognized and
* not ignored, throw it out. */
if (retval == ERR && !ignore_seq) {
if (win == edit)
statusbar(_("Unknown Command"));
beep();
}
}
break; break;
} }
} }
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment