Patch 8.2.1809
Problem:    Mapping some keys with Ctrl does not work properly.
Solution:   For terminal, GTK and Motif handle "@", "^" and "_" codes.
Files:      src/misc2.c, src/proto/misc2.pro, src/term.c, src/gui_gtk_x11.c,
            src/gui_x11.c, src/testdir/test_termcodes.vim


*** ../vim-8.2.1808/src/misc2.c 2020-09-27 13:16:41.697465066 +0200
--- src/misc2.c 2020-10-07 16:07:01.050562073 +0200
***************
*** 2947,2952 ****
--- 2947,2978 ----
  
  
  /*
+  * Some keys are used with Ctrl without Shift and are still expected to be
+  * mapped as if Shift was pressed:
+  * CTRL-2 is CTRL-@
+  * CTRL-6 is CTRL-^
+  * CTRL-- is CTRL-_
+  * Also, <C-H> and <C-h> mean the same thing, always use "H".
+  * Returns the possibly adjusted key.
+  */
+     int
+ may_adjust_key_for_ctrl(int modifiers, int key)
+ {
+     if (modifiers & MOD_MASK_CTRL)
+     {
+       if (ASCII_ISALPHA(key))
+           return TOUPPER_ASC(key);
+       if (key == '2')
+           return '@';
+       if (key == '6')
+           return '^';
+       if (key == '-')
+           return '_';
+     }
+     return key;
+ }
+ 
+ /*
   * Some keys already have Shift included, pass them as normal keys.
   * Not when Ctrl is also used, because <C-H> and <C-S-H> are different.
   * Also for <A-S-a> and <M-S-a>.
*** ../vim-8.2.1808/src/proto/misc2.pro 2020-07-31 22:04:59.776336159 +0200
--- src/proto/misc2.pro 2020-10-07 16:04:49.622929863 +0200
***************
*** 72,77 ****
--- 72,78 ----
  int trans_special(char_u **srcp, char_u *dst, int flags, int *did_simplify);
  int special_to_buf(int key, int modifiers, int keycode, char_u *dst);
  int find_special_key(char_u **srcp, int *modp, int flags, int *did_simplify);
+ int may_adjust_key_for_ctrl(int modifiers, int key);
  int may_remove_shift_modifier(int modifiers, int key);
  int extract_modifiers(int key, int *modp, int simplify, int *did_simplify);
  int find_special_key_in_table(int c);
*** ../vim-8.2.1808/src/term.c  2020-09-05 14:27:19.462565817 +0200
--- src/term.c  2020-10-07 16:07:59.622398743 +0200
***************
*** 4784,4798 ****
  
      modifiers = decode_modifiers(arg[1]);
  
      // May remove the shift modifier if it's already included in the key.
      modifiers = may_remove_shift_modifier(modifiers, key);
  
-     // When used with Ctrl we always make a letter upper case,
-     // so that mapping <C-H> and <C-h> are the same.  Typing
-     // <C-S-H> also uses "H" but modifier is different.
-     if ((modifiers & MOD_MASK_CTRL) && ASCII_ISALPHA(key))
-       key = TOUPPER_ASC(key);
- 
      // insert modifiers with KS_MODIFIER
      new_slen = modifiers2keycode(modifiers, &key, string);
  
--- 4784,4795 ----
  
      modifiers = decode_modifiers(arg[1]);
  
+     // Some keys need adjustment when the Ctrl modifier is used.
+     key = may_adjust_key_for_ctrl(modifiers, key);
+ 
      // May remove the shift modifier if it's already included in the key.
      modifiers = may_remove_shift_modifier(modifiers, key);
  
      // insert modifiers with KS_MODIFIER
      new_slen = modifiers2keycode(modifiers, &key, string);
  
*** ../vim-8.2.1808/src/gui_gtk_x11.c   2020-09-29 22:16:05.893669051 +0200
--- src/gui_gtk_x11.c   2020-10-07 16:03:53.499087464 +0200
***************
*** 1236,1246 ****
      }
      else
      {
!       // <C-H> and <C-h> mean the same thing, always use "H"
!       if ((modifiers & MOD_MASK_CTRL) && ASCII_ISALPHA(key))
!           key = TOUPPER_ASC(key);
  
!       // May remove the shift modifier if it's included in the key.
        modifiers = may_remove_shift_modifier(modifiers, key);
  
        len = mb_char2bytes(key, string);
--- 1236,1245 ----
      }
      else
      {
!       // Some keys need adjustment when the Ctrl modifier is used.
!       key = may_adjust_key_for_ctrl(modifiers, key);
  
!       // May remove the Shift modifier if it's included in the key.
        modifiers = may_remove_shift_modifier(modifiers, key);
  
        len = mb_char2bytes(key, string);
*** ../vim-8.2.1808/src/gui_x11.c       2020-09-27 13:16:41.697465066 +0200
--- src/gui_x11.c       2020-10-07 16:10:21.226112726 +0200
***************
*** 956,961 ****
--- 956,964 ----
      {
        len = mb_char2bytes(key, string);
  
+       // Some keys need adjustment when the Ctrl modifier is used.
+       key = may_adjust_key_for_ctrl(modifiers, key);
+ 
        // Remove the SHIFT modifier for keys where it's already included,
        // e.g., '(', '!' and '*'.
        modifiers = may_remove_shift_modifier(modifiers, key);
*** ../vim-8.2.1808/src/testdir/test_termcodes.vim      2020-09-27 
13:16:41.701465056 +0200
--- src/testdir/test_termcodes.vim      2020-10-07 15:55:46.100480288 +0200
***************
*** 2103,2108 ****
--- 2103,2126 ----
  func Test_mapping_works_with_ctrl()
    call RunTest_mapping_works_with_mods(function('GetEscCodeCSI27'), 'C', 5)
    call RunTest_mapping_works_with_mods(function('GetEscCodeCSIu'), 'C', 5)
+ 
+   new
+   set timeoutlen=10
+ 
+   " CTRL-@ actually produces the code for CTRL-2, which is converted
+   call RunTest_mapping_mods('<C-@>', '2', function('GetEscCodeCSI27'), 5)
+   call RunTest_mapping_mods('<C-@>', '2', function('GetEscCodeCSIu'), 5)
+ 
+   " CTRL-^ actually produces the code for CTRL-6, which is converted
+   call RunTest_mapping_mods('<C-^>', '6', function('GetEscCodeCSI27'), 5)
+   call RunTest_mapping_mods('<C-^>', '6', function('GetEscCodeCSIu'), 5)
+ 
+   " CTRL-_ actually produces the code for CTRL--, which is converted
+   call RunTest_mapping_mods('<C-_>', '-', function('GetEscCodeCSI27'), 5)
+   call RunTest_mapping_mods('<C-_>', '-', function('GetEscCodeCSIu'), 5)
+ 
+   bwipe!
+   set timeoutlen&
  endfunc
  
  func Test_mapping_works_with_shift_ctrl()
*** ../vim-8.2.1808/src/version.c       2020-10-07 12:58:41.157858444 +0200
--- src/version.c       2020-10-07 15:34:11.464936321 +0200
***************
*** 752,753 ****
--- 752,755 ----
  {   /* Add new patch number below this line */
+ /**/
+     1809,
  /**/

-- 
Well, you come from nothing, you go back to nothing...  What have you
lost?  Nothing!
                                -- Monty Python: The life of Brian

 /// Bram Moolenaar -- [email protected] -- http://www.Moolenaar.net   \\\
///        sponsor Vim, vote for features -- http://www.Vim.org/sponsor/ \\\
\\\  an exciting new programming language -- http://www.Zimbu.org        ///
 \\\            help me help AIDS victims -- http://ICCF-Holland.org    ///

-- 
-- 
You received this message from the "vim_dev" maillist.
Do not top-post! Type your reply below the text you are replying to.
For more information, visit http://www.vim.org/maillist.php

--- 
You received this message because you are subscribed to the Google Groups 
"vim_dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/vim_dev/202010071413.097ED4d92953827%40masaka.moolenaar.net.

Raspunde prin e-mail lui