diff src/terminal.c @ 18279:e8d1f3209dcd v8.1.2134

patch 8.1.2134: modifier keys are not always recognized Commit: https://github.com/vim/vim/commit/6a0299d8f4c7a64c64d60a6bb39cfe6eaf892247 Author: Bram Moolenaar <Bram@vim.org> Date: Thu Oct 10 21:14:03 2019 +0200 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.
author Bram Moolenaar <Bram@vim.org>
date Thu, 10 Oct 2019 21:15:04 +0200
parents c8a53c0daeed
children 506bf60a30a0
line wrap: on
line diff
--- a/src/terminal.c
+++ b/src/terminal.c
@@ -1371,11 +1371,13 @@ term_convert_key(term_T *term, int c, ch
 				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 @@ term_vgetc()
 {
     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 @@ term_win_entered()
 terminal_loop(int blocking)
 {
     int		c;
+    int		raw_c;
     int		termwinkey = 0;
     int		ret;
 #ifdef UNIX
@@ -2307,6 +2316,13 @@ terminal_loop(int blocking)
 	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 @@ terminal_loop(int blocking)
 		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