summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBram Moolenaar <Bram@vim.org>2018-11-02 11:59:15 +0100
committerBram Moolenaar <Bram@vim.org>2018-11-02 11:59:15 +0100
commit4dbc2627641a6b950c30c31cbf7b7e6c36da1927 (patch)
tree01a06742db92d299a694a3f7a3813df95834b593
parentf7acf2b63ce91ea802dbcf0618f0cdee80993468 (diff)
downloadvim-git-4dbc2627641a6b950c30c31cbf7b7e6c36da1927.tar.gz
patch 8.1.0504: when CTRL-C is mapped it triggers InsertLeavev8.1.0504
Problem: When CTRL-C is mapped it triggers InsertLeave. Solution: Make CTRL-C behave the same way when typed or used in a mapping.
-rw-r--r--src/edit.c7
-rw-r--r--src/testdir/test_edit.vim30
-rw-r--r--src/version.c2
3 files changed, 37 insertions, 2 deletions
diff --git a/src/edit.c b/src/edit.c
index 4b9bdffb4..239881ee5 100644
--- a/src/edit.c
+++ b/src/edit.c
@@ -1048,7 +1048,10 @@ doESCkey:
if (ins_esc(&count, cmdchar, nomove))
{
- if (cmdchar != 'r' && cmdchar != 'v')
+ // When CTRL-C was typed got_int will be set, with the result
+ // that the autocommands won't be executed. When mapped got_int
+ // is not set, but let's keep the behavior the same.
+ if (cmdchar != 'r' && cmdchar != 'v' && c != Ctrl_C)
ins_apply_autocmds(EVENT_INSERTLEAVE);
did_cursorhold = FALSE;
return (c == Ctrl_O);
@@ -2408,7 +2411,7 @@ has_compl_option(int dict_opt)
int
vim_is_ctrl_x_key(int c)
{
- /* Always allow ^R - let it's results then be checked */
+ // Always allow ^R - let its results then be checked
if (c == Ctrl_R)
return TRUE;
diff --git a/src/testdir/test_edit.vim b/src/testdir/test_edit.vim
index 651f1f8fa..63f58ae75 100644
--- a/src/testdir/test_edit.vim
+++ b/src/testdir/test_edit.vim
@@ -1409,3 +1409,33 @@ func Test_edit_alt()
bwipe XAltFile
call delete('XAltFile')
endfunc
+
+func Test_leave_insert_autocmd()
+ new
+ au InsertLeave * let g:did_au = 1
+ let g:did_au = 0
+ call feedkeys("afoo\<Esc>", 'tx')
+ call assert_equal(1, g:did_au)
+ call assert_equal('foo', getline(1))
+
+ let g:did_au = 0
+ call feedkeys("Sbar\<C-C>", 'tx')
+ call assert_equal(0, g:did_au)
+ call assert_equal('bar', getline(1))
+
+ inoremap x xx<Esc>
+ let g:did_au = 0
+ call feedkeys("Saax", 'tx')
+ call assert_equal(1, g:did_au)
+ call assert_equal('aaxx', getline(1))
+
+ inoremap x xx<C-C>
+ let g:did_au = 0
+ call feedkeys("Sbbx", 'tx')
+ call assert_equal(0, g:did_au)
+ call assert_equal('bbxx', getline(1))
+
+ bwipe!
+ au! InsertLeave
+ iunmap x
+endfunc
diff --git a/src/version.c b/src/version.c
index bc22e73da..2c06a0f39 100644
--- a/src/version.c
+++ b/src/version.c
@@ -793,6 +793,8 @@ static char *(features[]) =
static int included_patches[] =
{ /* Add new patch number below this line */
/**/
+ 504,
+/**/
503,
/**/
502,