]> granicus.if.org Git - vim/commitdiff
patch 8.2.2819: finishing an abbreviation with multi-byte char may not work v8.2.2819
authorBram Moolenaar <Bram@vim.org>
Fri, 30 Apr 2021 17:43:11 +0000 (19:43 +0200)
committerBram Moolenaar <Bram@vim.org>
Fri, 30 Apr 2021 17:43:11 +0000 (19:43 +0200)
Problem:    Finishing an abbreviation with a multi-byte char may not work.
Solution:   Escape K_SPECIAL in the typed character. (closes #8160)

src/map.c
src/testdir/test_mapping.vim
src/version.c

index f142db09c43285421c5a785a08745c21b61d26ad..31742c13b30d45018e9eafe3113a89db2cc7e869 100644 (file)
--- a/src/map.c
+++ b/src/map.c
@@ -1540,10 +1540,23 @@ check_abbr(
                        tb[j++] = Ctrl_V;       // special char needs CTRL-V
                    if (has_mbyte)
                    {
+                       int     newlen;
+                       char_u  *escaped;
+
                        // if ABBR_OFF has been added, remove it here
                        if (c >= ABBR_OFF)
                            c -= ABBR_OFF;
-                       j += (*mb_char2bytes)(c, tb + j);
+                       newlen = (*mb_char2bytes)(c, tb + j);
+                       tb[j + newlen] = NUL;
+                       // Need to escape K_SPECIAL.
+                       escaped = vim_strsave_escape_csi(tb + j);
+                       if (escaped != NULL)
+                       {
+                           newlen = STRLEN(escaped);
+                           mch_memmove(tb + j, escaped, newlen);
+                           j += newlen;
+                           vim_free(escaped);
+                       }
                    }
                    else
                        tb[j++] = c;
index c93562b0714a89d3ccb56a5fdba59c5d773a693f..7fcd8062c8d8ca8c6aeeb583efe240d293dea913 100644 (file)
@@ -1402,4 +1402,13 @@ func Test_script_local_remap()
   bwipe!
 endfunc
 
+func Test_abbreviate_multi_byte()
+  new
+  iabbrev foo bar
+  call feedkeys("ifoo…\<Esc>", 'xt')
+  call assert_equal("bar…", getline(1))
+  iunabbrev foo
+  bwipe!
+endfunc
+
 " vim: shiftwidth=2 sts=2 expandtab
index f1d55324d52dbf7ee8a4e45ffbde60029d98874b..b1ba0a11975065c5c4cbce6a28d82afd355a72bf 100644 (file)
@@ -750,6 +750,8 @@ static char *(features[]) =
 
 static int included_patches[] =
 {   /* Add new patch number below this line */
+/**/
+    2819,
 /**/
     2818,
 /**/