forked from aniani/vim
patch 9.1.0511: CursorMovedC triggered wrongly with setcmdpos()
Problem: CursorMovedC triggered wrongly with setcmdpos() (after v9.1.0507) Solution: Remove the premature triggering. Also don't trigger when cursor didn't move. (zeertzjq) closes: #15064 Signed-off-by: zeertzjq <zeertzjq@outlook.com> Signed-off-by: Christian Brabandt <cb@256bit.org>
This commit is contained in:
parent
17e0a1969d
commit
bc6f96708e
@ -1,4 +1,4 @@
|
|||||||
*autocmd.txt* For Vim version 9.1. Last change: 2024 Jun 20
|
*autocmd.txt* For Vim version 9.1. Last change: 2024 Jun 21
|
||||||
|
|
||||||
|
|
||||||
VIM REFERENCE MANUAL by Bram Moolenaar
|
VIM REFERENCE MANUAL by Bram Moolenaar
|
||||||
@ -751,7 +751,8 @@ CursorMoved After the cursor was moved in Normal or Visual
|
|||||||
that is slow.
|
that is slow.
|
||||||
*CursorMovedC*
|
*CursorMovedC*
|
||||||
CursorMovedC After the cursor was moved in the command
|
CursorMovedC After the cursor was moved in the command
|
||||||
line. Be careful not to mess up the
|
line while the text in the command line hasn't
|
||||||
|
changed. Be careful not to mess up the
|
||||||
command line, it may cause Vim to lock up.
|
command line, it may cause Vim to lock up.
|
||||||
<afile> is set to a single character,
|
<afile> is set to a single character,
|
||||||
indicating the type of command-line.
|
indicating the type of command-line.
|
||||||
|
@ -1586,7 +1586,7 @@ getcmdline_int(
|
|||||||
int res;
|
int res;
|
||||||
int save_msg_scroll = msg_scroll;
|
int save_msg_scroll = msg_scroll;
|
||||||
int save_State = State; // remember State when called
|
int save_State = State; // remember State when called
|
||||||
int save_cmdspos = ccline.cmdspos;
|
int prev_cmdpos = -1;
|
||||||
int some_key_typed = FALSE; // one of the keys was typed
|
int some_key_typed = FALSE; // one of the keys was typed
|
||||||
// mouse drag and release events are ignored, unless they are
|
// mouse drag and release events are ignored, unless they are
|
||||||
// preceded with a mouse down event
|
// preceded with a mouse down event
|
||||||
@ -2475,15 +2475,18 @@ getcmdline_int(
|
|||||||
*/
|
*/
|
||||||
cmdline_not_changed:
|
cmdline_not_changed:
|
||||||
// Trigger CursorMovedC autocommands.
|
// Trigger CursorMovedC autocommands.
|
||||||
if (ccline.cmdspos != save_cmdspos)
|
if (ccline.cmdpos != prev_cmdpos)
|
||||||
|
{
|
||||||
trigger_cmd_autocmd(cmdline_type, EVENT_CURSORMOVEDC);
|
trigger_cmd_autocmd(cmdline_type, EVENT_CURSORMOVEDC);
|
||||||
|
prev_cmdpos = ccline.cmdpos;
|
||||||
|
}
|
||||||
#ifdef FEAT_SEARCH_EXTRA
|
#ifdef FEAT_SEARCH_EXTRA
|
||||||
if (!is_state.incsearch_postponed)
|
if (!is_state.incsearch_postponed)
|
||||||
continue;
|
continue;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
cmdline_changed:
|
cmdline_changed:
|
||||||
|
prev_cmdpos = ccline.cmdpos;
|
||||||
#ifdef FEAT_SEARCH_EXTRA
|
#ifdef FEAT_SEARCH_EXTRA
|
||||||
// If the window changed incremental search state is not valid.
|
// If the window changed incremental search state is not valid.
|
||||||
if (is_state.winid != curwin->w_id)
|
if (is_state.winid != curwin->w_id)
|
||||||
@ -4321,9 +4324,6 @@ set_cmdline_pos(
|
|||||||
else
|
else
|
||||||
new_cmdpos = pos;
|
new_cmdpos = pos;
|
||||||
|
|
||||||
// Trigger CursorMovedC autocommands.
|
|
||||||
trigger_cmd_autocmd(get_cmdline_type(), EVENT_CURSORMOVEDC);
|
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -2097,20 +2097,28 @@ func Test_Cmdline()
|
|||||||
au! CmdlineLeave
|
au! CmdlineLeave
|
||||||
let &shellslash = save_shellslash
|
let &shellslash = save_shellslash
|
||||||
|
|
||||||
au! CursorMovedC : let g:pos = getcmdpos()
|
au! CursorMovedC : let g:pos += [getcmdpos()]
|
||||||
let g:pos = 0
|
let g:pos = []
|
||||||
call feedkeys(":hello\<Left>\<ESC>", 'xt')
|
call feedkeys(":hello\<Left>\<C-R>=''\<CR>\<Left>\<Right>\<Esc>", 'xt')
|
||||||
call assert_equal(5, g:pos)
|
call assert_equal([5, 4, 5], g:pos)
|
||||||
call feedkeys(":12345678\<C-R>=setcmdpos(3)\<CR>\<ESC>", 'xt')
|
let g:pos = []
|
||||||
call assert_equal(3, g:pos)
|
call feedkeys(":12345678\<C-R>=setcmdpos(3)??''\<CR>\<Esc>", 'xt')
|
||||||
|
call assert_equal([3], g:pos)
|
||||||
|
let g:pos = []
|
||||||
|
call feedkeys(":12345678\<C-R>=setcmdpos(3)??''\<CR>\<Left>\<Esc>", 'xt')
|
||||||
|
call assert_equal([3, 2], g:pos)
|
||||||
au! CursorMovedC
|
au! CursorMovedC
|
||||||
|
|
||||||
" CursorMovedC changes the cursor position.
|
" setcmdpos() is no-op inside an autocommand
|
||||||
au! CursorMovedC : let g:pos = getcmdpos() | call setcmdpos(getcmdpos()-1)
|
au! CursorMovedC : let g:pos += [getcmdpos()] | call setcmdpos(1)
|
||||||
let g:pos = 0
|
let g:pos = []
|
||||||
call feedkeys(":hello\<Left>\<ESC>", 'xt')
|
call feedkeys(":hello\<Left>\<Left>\<Esc>", 'xt')
|
||||||
call assert_equal(5, g:pos)
|
call assert_equal([5, 4], g:pos)
|
||||||
au! CursorMovedC
|
au! CursorMovedC
|
||||||
|
|
||||||
|
unlet g:entered
|
||||||
|
unlet g:left
|
||||||
|
unlet g:pos
|
||||||
endfunc
|
endfunc
|
||||||
|
|
||||||
" Test for BufWritePre autocommand that deletes or unloads the buffer.
|
" Test for BufWritePre autocommand that deletes or unloads the buffer.
|
||||||
|
@ -704,6 +704,8 @@ static char *(features[]) =
|
|||||||
|
|
||||||
static int included_patches[] =
|
static int included_patches[] =
|
||||||
{ /* Add new patch number below this line */
|
{ /* Add new patch number below this line */
|
||||||
|
/**/
|
||||||
|
511,
|
||||||
/**/
|
/**/
|
||||||
510,
|
510,
|
||||||
/**/
|
/**/
|
||||||
|
Loading…
x
Reference in New Issue
Block a user