]> git.ipfire.org Git - thirdparty/vim.git/commitdiff
patch 9.1.0580: :lmap mapping for keypad key not applied when typed in Select mode v9.1.0580
authorzeertzjq <zeertzjq@outlook.com>
Sat, 13 Jul 2024 17:06:44 +0000 (19:06 +0200)
committerChristian Brabandt <cb@256bit.org>
Sat, 13 Jul 2024 17:06:44 +0000 (19:06 +0200)
Problem:  An :lmap mapping for a printable keypad key is not applied
          when typing it in Select mode.
Solution: Change keypad key to ASCII after setting vgetc_char.
          (zeertzjq)

closes: #15245

Signed-off-by: zeertzjq <zeertzjq@outlook.com>
Signed-off-by: Christian Brabandt <cb@256bit.org>
src/getchar.c
src/testdir/test_selectmode.vim
src/version.c

index 0a37b7b111a9bdfcee48e6659e22896957d5e1c5..9d54377cc137cf9828f09fe9b6b0b67b7b196039 100644 (file)
@@ -1999,6 +1999,43 @@ vgetc(void)
 #endif
            }
 
+           // For a multi-byte character get all the bytes and return the
+           // converted character.
+           // Note: This will loop until enough bytes are received!
+           if (has_mbyte && (n = MB_BYTE2LEN_CHECK(c)) > 1)
+           {
+               ++no_mapping;
+               buf[0] = c;
+               for (i = 1; i < n; ++i)
+               {
+                   buf[i] = vgetorpeek(TRUE);
+                   if (buf[i] == K_SPECIAL
+#ifdef FEAT_GUI
+                           || (buf[i] == CSI)
+#endif
+                           )
+                   {
+                       // Must be a K_SPECIAL - KS_SPECIAL - KE_FILLER
+                       // sequence, which represents a K_SPECIAL (0x80),
+                       // or a CSI - KS_EXTRA - KE_CSI sequence, which
+                       // represents a CSI (0x9B),
+                       // or a K_SPECIAL - KS_EXTRA - KE_CSI, which is CSI
+                       // too.
+                       c = vgetorpeek(TRUE);
+                       if (vgetorpeek(TRUE) == KE_CSI && c == KS_EXTRA)
+                           buf[i] = CSI;
+                   }
+               }
+               --no_mapping;
+               c = (*mb_ptr2char)(buf);
+           }
+
+           if (vgetc_char == 0)
+           {
+               vgetc_mod_mask = mod_mask;
+               vgetc_char = c;
+           }
+
            // a keypad or special function key was not mapped, use it like
            // its ASCII equivalent
            switch (c)
@@ -2062,43 +2099,6 @@ vgetc(void)
                case K_XRIGHT:  c = K_RIGHT; break;
            }
 
-           // For a multi-byte character get all the bytes and return the
-           // converted character.
-           // Note: This will loop until enough bytes are received!
-           if (has_mbyte && (n = MB_BYTE2LEN_CHECK(c)) > 1)
-           {
-               ++no_mapping;
-               buf[0] = c;
-               for (i = 1; i < n; ++i)
-               {
-                   buf[i] = vgetorpeek(TRUE);
-                   if (buf[i] == K_SPECIAL
-#ifdef FEAT_GUI
-                           || (buf[i] == CSI)
-#endif
-                           )
-                   {
-                       // Must be a K_SPECIAL - KS_SPECIAL - KE_FILLER
-                       // sequence, which represents a K_SPECIAL (0x80),
-                       // or a CSI - KS_EXTRA - KE_CSI sequence, which
-                       // represents a CSI (0x9B),
-                       // or a K_SPECIAL - KS_EXTRA - KE_CSI, which is CSI
-                       // too.
-                       c = vgetorpeek(TRUE);
-                       if (vgetorpeek(TRUE) == KE_CSI && c == KS_EXTRA)
-                           buf[i] = CSI;
-                   }
-               }
-               --no_mapping;
-               c = (*mb_ptr2char)(buf);
-           }
-
-           if (vgetc_char == 0)
-           {
-               vgetc_mod_mask = mod_mask;
-               vgetc_char = c;
-           }
-
            break;
        }
 
index bf1b52b3254e96d2d9016ddcb27997cdb3433f4b..63aa0b9a191f6e2eeab5e39fac0cbdd4588f398f 100644 (file)
@@ -321,4 +321,20 @@ func Test_ins_ctrl_o_in_insert_mode_resets_selectmode()
   bwipe!
 endfunc
 
+" Test that an :lmap mapping for a printable keypad key is applied when typing
+" it in Select mode.
+func Test_selectmode_keypad_lmap()
+  new
+  lnoremap <buffer> <kPoint> ???
+  lnoremap <buffer> <kEnter> !!!
+  setlocal iminsert=1
+  call setline(1, 'abcdef')
+  call feedkeys("gH\<kPoint>\<Esc>", 'tx')
+  call assert_equal(['???'], getline(1, '$'))
+  call feedkeys("gH\<kEnter>\<Esc>", 'tx')
+  call assert_equal(['!!!'], getline(1, '$'))
+
+  bwipe!
+endfunc
+
 " vim: shiftwidth=2 sts=2 expandtab
index ac04272c6feb90ed75ebbebc55e9a07ee1c66048..b117443cad834d28b2da6a08db54bd54907daf07 100644 (file)
@@ -704,6 +704,8 @@ static char *(features[]) =
 
 static int included_patches[] =
 {   /* Add new patch number below this line */
+/**/
+    580,
 /**/
     579,
 /**/