changeset 24559:839145e0fdaa v8.2.2819

patch 8.2.2819: finishing an abbreviation with multi-byte char may not work Commit: https://github.com/vim/vim/commit/4934ed34c3e2090d1963c89c629cd3ce81d3ecd1 Author: Bram Moolenaar <Bram@vim.org> Date: Fri Apr 30 19:43:11 2021 +0200 patch 8.2.2819: finishing an abbreviation with multi-byte char may not work Problem: Finishing an abbreviation with a multi-byte char may not work. Solution: Escape K_SPECIAL in the typed character. (closes https://github.com/vim/vim/issues/8160)
author Bram Moolenaar <Bram@vim.org>
date Fri, 30 Apr 2021 19:45:04 +0200
parents 9a6a4aa70490
children dec4794e5af6
files src/map.c src/testdir/test_mapping.vim src/version.c
diffstat 3 files changed, 25 insertions(+), 1 deletions(-) [+]
line wrap: on
line diff
--- 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;
--- a/src/testdir/test_mapping.vim
+++ b/src/testdir/test_mapping.vim
@@ -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
--- a/src/version.c
+++ b/src/version.c
@@ -751,6 +751,8 @@ static char *(features[]) =
 static int included_patches[] =
 {   /* Add new patch number below this line */
 /**/
+    2819,
+/**/
     2818,
 /**/
     2817,