summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBram Moolenaar <Bram@vim.org>2022-10-18 15:10:11 +0100
committerBram Moolenaar <Bram@vim.org>2022-10-18 15:10:11 +0100
commit61c4b04799bf114cadc3bbf212ae8b2ad22a6980 (patch)
tree6d5174bccf9475acadd62d8efe58767bd557b5df
parent9298a996fc54e483dc29c0700edf3c5fe9d0f6a9 (diff)
downloadvim-git-61c4b04799bf114cadc3bbf212ae8b2ad22a6980.tar.gz
patch 9.0.0788: ModeChanged autocmd not executed when Visual ends with CTRL-Cv9.0.0788
Problem: ModeChanged autocmd not executed when Visual mode is ended with CTRL-C. Solution: Do not trigger the autocmd when got_int is set. (closes #11394)
-rw-r--r--src/misc1.c9
-rw-r--r--src/testdir/test_autocmd.vim12
-rw-r--r--src/version.c2
3 files changed, 22 insertions, 1 deletions
diff --git a/src/misc1.c b/src/misc1.c
index ee79e694a..c968bf67f 100644
--- a/src/misc1.c
+++ b/src/misc1.c
@@ -330,6 +330,7 @@ get_last_leader_offset(char_u *line, char_u **flags)
/*
* Return the number of window lines occupied by buffer line "lnum".
+ * Includes any filler lines.
*/
int
plines(linenr_T lnum)
@@ -349,6 +350,10 @@ plines_win(
return plines_win_nofill(wp, lnum, winheight) + diff_check_fill(wp, lnum);
}
+/*
+ * Return the number of window lines occupied by buffer line "lnum".
+ * Does not include filler lines.
+ */
int
plines_nofill(linenr_T lnum)
{
@@ -2754,7 +2759,9 @@ may_trigger_modechanged()
char_u curr_mode[MODE_MAX_LENGTH];
char_u pattern_buf[2 * MODE_MAX_LENGTH];
- if (!has_modechanged())
+ // Skip this when got_int is set, the autocommand will not be executed.
+ // Better trigger it next time.
+ if (!has_modechanged() || got_int)
return;
get_mode(curr_mode);
diff --git a/src/testdir/test_autocmd.vim b/src/testdir/test_autocmd.vim
index 3698fd57e..0706e7307 100644
--- a/src/testdir/test_autocmd.vim
+++ b/src/testdir/test_autocmd.vim
@@ -3429,6 +3429,18 @@ func Test_mode_changes()
unlet g:n_to_c
unlet g:c_to_n
+ let g:n_to_v = 0
+ au ModeChanged n:v let g:n_to_v += 1
+ let g:v_to_n = 0
+ au ModeChanged v:n let g:v_to_n += 1
+ let g:mode_seq += ['v', 'n']
+ call feedkeys("v\<C-C>", 'tnix')
+ call assert_equal(len(g:mode_seq) - 1, g:index)
+ call assert_equal(1, g:n_to_v)
+ call assert_equal(1, g:v_to_n)
+ unlet g:n_to_v
+ unlet g:v_to_n
+
au! ModeChanged
delfunc TestMode
unlet! g:mode_seq
diff --git a/src/version.c b/src/version.c
index 87baf994b..1c511f94b 100644
--- a/src/version.c
+++ b/src/version.c
@@ -696,6 +696,8 @@ static char *(features[]) =
static int included_patches[] =
{ /* Add new patch number below this line */
/**/
+ 788,
+/**/
787,
/**/
786,