bindings: allow to bind shifted Meta+letter combinations with Sh-M-X
As long as the user does not define any Sh-M-X bindings in their nanorc, <Shift> and <CapsLock> will not have any effect on <Alt+letter> combos. But as soon as any Sh-M-X combination is bound, <Shift+Alt+letter> will be seen as different from the unshifted keystroke. This kind of fulfills https://savannah.gnu.org/bugs/?54659. Requested-by: Peter Passchier <peter@passchier.net>master
parent
f7a3b996fa
commit
1cd5005d06
11
src/global.c
11
src/global.c
|
@ -33,6 +33,8 @@ volatile sig_atomic_t the_window_resized = FALSE;
|
||||||
|
|
||||||
bool on_a_vt = FALSE;
|
bool on_a_vt = FALSE;
|
||||||
/* Whether we're running on a Linux console (a VT). */
|
/* Whether we're running on a Linux console (a VT). */
|
||||||
|
bool shifted_metas = FALSE;
|
||||||
|
/* Whether any Sh-M-<letter> combo has been bound. */
|
||||||
|
|
||||||
bool meta_key;
|
bool meta_key;
|
||||||
/* Whether the current keystroke is a Meta key. */
|
/* Whether the current keystroke is a Meta key. */
|
||||||
|
@ -505,6 +507,13 @@ int keycode_from_string(const char *keystring)
|
||||||
return (int)' ';
|
return (int)' ';
|
||||||
else
|
else
|
||||||
return -1;
|
return -1;
|
||||||
|
#ifdef ENABLE_NANORC
|
||||||
|
} else if (strncasecmp(keystring, "Sh-M-", 5) == 0 &&
|
||||||
|
'a' <= (keystring[5] | 0x20) && (keystring[5] | 0x20) <= 'z' &&
|
||||||
|
keystring[6] == '\0') {
|
||||||
|
shifted_metas = TRUE;
|
||||||
|
return (keystring[5] & 0x5F);
|
||||||
|
#endif
|
||||||
} else if (keystring[0] == 'F') {
|
} else if (keystring[0] == 'F') {
|
||||||
int fn = atoi(&keystring[1]);
|
int fn = atoi(&keystring[1]);
|
||||||
if (fn < 1 || fn > 24)
|
if (fn < 1 || fn > 24)
|
||||||
|
@ -522,7 +531,7 @@ int keycode_from_string(const char *keystring)
|
||||||
void assign_keyinfo(keystruct *s, const char *keystring, const int keycode)
|
void assign_keyinfo(keystruct *s, const char *keystring, const int keycode)
|
||||||
{
|
{
|
||||||
s->keystr = keystring;
|
s->keystr = keystring;
|
||||||
s->meta = (keystring[0] == 'M' && keycode < 0x7F);
|
s->meta = ((keystring[0] == 'M' || keystring[0] == 'S') && keycode < 0x7F);
|
||||||
s->keycode = (keycode ? keycode : keycode_from_string(keystring));
|
s->keycode = (keycode ? keycode : keycode_from_string(keystring));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1359,6 +1359,10 @@ void unbound_key(int code)
|
||||||
#ifndef NANO_TINY
|
#ifndef NANO_TINY
|
||||||
else if (code < 0x20)
|
else if (code < 0x20)
|
||||||
statusline(ALERT, _("Unbindable key: M-^%c"), code + 0x40);
|
statusline(ALERT, _("Unbindable key: M-^%c"), code + 0x40);
|
||||||
|
#endif
|
||||||
|
#ifdef ENABLE_NANORC
|
||||||
|
else if (shifted_metas && 'A' <= code && code <= 'Z')
|
||||||
|
statusline(ALERT, _("Unbound key: Sh-M-%c"), code);
|
||||||
#endif
|
#endif
|
||||||
else
|
else
|
||||||
statusline(ALERT, _("Unbound key: M-%c"), toupper(code));
|
statusline(ALERT, _("Unbound key: M-%c"), toupper(code));
|
||||||
|
|
|
@ -27,6 +27,7 @@ extern volatile sig_atomic_t the_window_resized;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
extern bool on_a_vt;
|
extern bool on_a_vt;
|
||||||
|
extern bool shifted_metas;
|
||||||
|
|
||||||
extern bool meta_key;
|
extern bool meta_key;
|
||||||
extern bool shift_held;
|
extern bool shift_held;
|
||||||
|
|
|
@ -391,7 +391,7 @@ int parse_kbinput(WINDOW *win)
|
||||||
* meta key sequence mode. */
|
* meta key sequence mode. */
|
||||||
if (!solitary || (keycode >= 0x20 && keycode < 0x7F))
|
if (!solitary || (keycode >= 0x20 && keycode < 0x7F))
|
||||||
meta_key = TRUE;
|
meta_key = TRUE;
|
||||||
retval = tolower(keycode);
|
retval = (shifted_metas) ? keycode : tolower(keycode);
|
||||||
} else
|
} else
|
||||||
/* One escape followed by a non-escape, and there
|
/* One escape followed by a non-escape, and there
|
||||||
* are more codes waiting: escape sequence mode. */
|
* are more codes waiting: escape sequence mode. */
|
||||||
|
@ -466,7 +466,7 @@ int parse_kbinput(WINDOW *win)
|
||||||
* or control character sequence mode. */
|
* or control character sequence mode. */
|
||||||
if (!solitary) {
|
if (!solitary) {
|
||||||
meta_key = TRUE;
|
meta_key = TRUE;
|
||||||
retval = tolower(keycode);
|
retval = (shifted_metas) ? keycode : tolower(keycode);
|
||||||
} else
|
} else
|
||||||
retval = get_control_kbinput(keycode);
|
retval = get_control_kbinput(keycode);
|
||||||
else {
|
else {
|
||||||
|
@ -495,7 +495,7 @@ int parse_kbinput(WINDOW *win)
|
||||||
if (key_buffer_len == 0) {
|
if (key_buffer_len == 0) {
|
||||||
if (!solitary) {
|
if (!solitary) {
|
||||||
meta_key = TRUE;
|
meta_key = TRUE;
|
||||||
retval = tolower(keycode);
|
retval = (shifted_metas) ? keycode : tolower(keycode);
|
||||||
} else
|
} else
|
||||||
/* Three escapes followed by a non-escape, and no
|
/* Three escapes followed by a non-escape, and no
|
||||||
* other codes are waiting: normal input mode. */
|
* other codes are waiting: normal input mode. */
|
||||||
|
|
Loading…
Reference in New Issue