patch 8.1.2134: modifier keys are not always recognized
Problem: Modifier keys are not always recognized.
Solution: Handle key codes generated by xterm with modifyOtherKeys set.
Add this to libvterm so we can debug it.
diff --git a/src/terminal.c b/src/terminal.c
index 42a80cd..a992b44 100644
--- a/src/terminal.c
+++ b/src/terminal.c
@@ -1371,11 +1371,13 @@
break;
}
+ // add modifiers for the typed key
+ mod |= mod_mask;
+
/*
* Convert special keys to vterm keys:
* - Write keys to vterm: vterm_keyboard_key()
* - Write output to channel.
- * TODO: use mod_mask
*/
if (key != VTERM_KEY_NONE)
/* Special key, let vterm convert it. */
@@ -1902,15 +1904,21 @@
{
int c;
int save_State = State;
+ int modify_other_keys =
+ vterm_is_modify_other_keys(curbuf->b_term->tl_vterm);
State = TERMINAL;
got_int = FALSE;
#ifdef MSWIN
ctrl_break_was_pressed = FALSE;
#endif
+ if (modify_other_keys)
+ ++no_reduce_keys;
c = vgetc();
got_int = FALSE;
State = save_State;
+ if (modify_other_keys)
+ --no_reduce_keys;
return c;
}
@@ -2255,6 +2263,7 @@
terminal_loop(int blocking)
{
int c;
+ int raw_c;
int termwinkey = 0;
int ret;
#ifdef UNIX
@@ -2307,6 +2316,13 @@
if (c == K_IGNORE)
continue;
+ // vgetc may not include CTRL in the key when modify_other_keys is set.
+ raw_c = c;
+ if ((mod_mask & MOD_MASK_CTRL)
+ && ((c >= '`' && c <= 0x7f)
+ || (c >= '@' && c <= '_')))
+ c &= 0x1f;
+
#ifdef UNIX
/*
* The shell or another program may change the tty settings. Getting
@@ -2417,7 +2433,7 @@
c = wc;
}
# endif
- if (send_keys_to_term(curbuf->b_term, c, TRUE) != OK)
+ if (send_keys_to_term(curbuf->b_term, raw_c, TRUE) != OK)
{
if (c == K_MOUSEMOVE)
/* We are sure to come back here, don't reset the cursor color