]> git.ipfire.org Git - thirdparty/vim.git/commitdiff
patch 9.1.0035: i_CTRL-] triggers InsertCharPre v9.1.0035
authoraltermo <>
Tue, 16 Jan 2024 16:25:17 +0000 (17:25 +0100)
committerChristian Brabandt <cb@256bit.org>
Tue, 16 Jan 2024 16:25:17 +0000 (17:25 +0100)
Problem:  i_CTRL-] triggers InsertCharPre
Solution: Return if CTRL-] is received. InsertCharPre
          is supposed to be only used for chars to be inserted
          but i_CTRL-] triggers expansion and is not inserted
          into the buffer (altermo)

closes: #13853
closes: #13864

Signed-off-by: altermo
Signed-off-by: Christian Brabandt <cb@256bit.org>
src/edit.c
src/testdir/test_edit.vim
src/version.c

index cb6ae7ee9b5720c7031c2335abf125962b67e7cc..672028bbbae7f1d298b1723952b2648a8b47dd1c 100644 (file)
@@ -5371,6 +5371,9 @@ do_insert_char_pre(int c)
     if (!has_insertcharpre())
        return NULL;
 
+    if (c == Ctrl_RSB)
+       return NULL;
+
     if (has_mbyte)
        buf[(*mb_char2bytes)(c, buf)] = NUL;
     else
index d662f4a0f1478ea0b83b6fa0361a249b77444f5a..36e0525563c39d71f2f1c6d9adc62dc22a34a95a 100644 (file)
@@ -2123,4 +2123,39 @@ func Test_edit_shift_bs()
   call StopVimInTerminal(buf)
 endfunc
 
+func Test_edit_Ctrl_RSB()
+  new
+  let g:triggered = []
+  autocmd InsertCharPre <buffer> let g:triggered += [v:char]
+
+  " i_CTRL-] should not trigger InsertCharPre
+  exe "normal! A\<C-]>"
+  call assert_equal([], g:triggered)
+
+  " i_CTRL-] should expand abbreviations but not trigger InsertCharPre
+  inoreabbr <buffer> f foo
+  exe "normal! Af\<C-]>a"
+  call assert_equal(['f', 'f', 'o', 'o', 'a'], g:triggered)
+  call assert_equal('fooa', getline(1))
+
+  " CTRL-] followed by i_CTRL-V should not expand abbreviations
+  " i_CTRL-V doesn't trigger InsertCharPre
+  call setline(1, '')
+  exe "normal! Af\<C-V>\<C-]>"
+  call assert_equal("f\<C-]>", getline(1))
+
+  let g:triggered = []
+  call setline(1, '')
+
+  " Also test assigning to v:char
+  autocmd InsertCharPre <buffer> let v:char = 'f'
+  exe "normal! Ag\<C-]>h"
+  call assert_equal(['g', 'f', 'o', 'o', 'h'], g:triggered)
+  call assert_equal('ffff', getline(1))
+
+  autocmd! InsertCharPre
+  unlet g:triggered
+  bwipe!
+endfunc
+
 " vim: shiftwidth=2 sts=2 expandtab
index 425d609eb6679801fd5800c40af9cd1c38d61fc7..1263ee8cd0f7898883a30cc9dd0ee53901c53a9d 100644 (file)
@@ -704,6 +704,8 @@ static char *(features[]) =
 
 static int included_patches[] =
 {   /* Add new patch number below this line */
+/**/
+    35,
 /**/
     34,
 /**/