vim-patch:9.0.1371: ballooneval interferes with Insert completion (#22487)

Problem:    Ballooneval interferes with Insert completion.
Solution:   Ignore mouse-move events when completing. (closes vim/vim#12094,
            closes vim/vim#12092)

440d4cb55b
This commit is contained in:
zeertzjq 2023-03-03 07:44:16 +08:00 committed by GitHub
parent fdb6b4d2e7
commit 361de6d54d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 55 additions and 7 deletions

View File

@ -2096,10 +2096,10 @@ bool ins_compl_prep(int c)
edit_submode_extra = NULL;
}
// Ignore end of Select mode mapping and mouse scroll buttons.
// Ignore end of Select mode mapping and mouse scroll/movement.
if (c == K_SELECT || c == K_MOUSEDOWN || c == K_MOUSEUP
|| c == K_MOUSELEFT || c == K_MOUSERIGHT || c == K_EVENT
|| c == K_COMMAND || c == K_LUA) {
|| c == K_MOUSELEFT || c == K_MOUSERIGHT || c == K_MOUSEMOVE
|| c == K_EVENT || c == K_COMMAND || c == K_LUA) {
return retval;
}
@ -3043,7 +3043,7 @@ static void get_next_spell_completion(linenr_T lnum)
/// @param cur_match_pos current match position
/// @param match_len
/// @param cont_s_ipos next ^X<> will set initial_pos
static char *ins_comp_get_next_word_or_line(buf_T *ins_buf, pos_T *cur_match_pos, int *match_len,
static char *ins_compl_get_next_word_or_line(buf_T *ins_buf, pos_T *cur_match_pos, int *match_len,
bool *cont_s_ipos)
{
*match_len = 0;
@ -3206,7 +3206,7 @@ static int get_next_default_completion(ins_compl_next_state_T *st, pos_T *start_
continue;
}
int len;
char *ptr = ins_comp_get_next_word_or_line(st->ins_buf, st->cur_match_pos,
char *ptr = ins_compl_get_next_word_or_line(st->ins_buf, st->cur_match_pos,
&len, &cont_s_ipos);
if (ptr == NULL) {
continue;

View File

@ -375,6 +375,54 @@ func Test_completefunc_info()
set completefunc&
endfunc
" Test that mouse scrolling/movement should not interrupt completion.
func Test_mouse_scroll_move_during_completion()
new
com! -buffer TestCommand1 echo 'TestCommand1'
com! -buffer TestCommand2 echo 'TestCommand2'
call setline(1, ['', '', '', '', ''])
call cursor(5, 1)
" Without completion menu scrolling can move text.
set completeopt-=menu wrap
call feedkeys("ccT\<C-X>\<C-V>\<ScrollWheelDown>\<C-V>", 'tx')
call assert_equal('TestCommand2', getline('.'))
call assert_notequal(1, winsaveview().topline)
call feedkeys("ccT\<C-X>\<C-V>\<ScrollWheelUp>\<C-V>", 'tx')
call assert_equal('TestCommand2', getline('.'))
call assert_equal(1, winsaveview().topline)
set nowrap
call feedkeys("ccT\<C-X>\<C-V>\<ScrollWheelRight>\<C-V>", 'tx')
call assert_equal('TestCommand2', getline('.'))
call assert_notequal(0, winsaveview().leftcol)
call feedkeys("ccT\<C-X>\<C-V>\<ScrollWheelLeft>\<C-V>", 'tx')
call assert_equal('TestCommand2', getline('.'))
call assert_equal(0, winsaveview().leftcol)
call feedkeys("ccT\<C-X>\<C-V>\<MouseMove>\<C-V>", 'tx')
call assert_equal('TestCommand2', getline('.'))
" With completion menu scrolling cannot move text.
set completeopt+=menu wrap
call feedkeys("ccT\<C-X>\<C-V>\<ScrollWheelDown>\<C-V>", 'tx')
call assert_equal('TestCommand2', getline('.'))
call assert_equal(1, winsaveview().topline)
call feedkeys("ccT\<C-X>\<C-V>\<ScrollWheelUp>\<C-V>", 'tx')
call assert_equal('TestCommand2', getline('.'))
call assert_equal(1, winsaveview().topline)
set nowrap
call feedkeys("ccT\<C-X>\<C-V>\<ScrollWheelRight>\<C-V>", 'tx')
call assert_equal('TestCommand2', getline('.'))
call assert_equal(0, winsaveview().leftcol)
call feedkeys("ccT\<C-X>\<C-V>\<ScrollWheelLeft>\<C-V>", 'tx')
call assert_equal('TestCommand2', getline('.'))
call assert_equal(0, winsaveview().leftcol)
call feedkeys("ccT\<C-X>\<C-V>\<MouseMove>\<C-V>", 'tx')
call assert_equal('TestCommand2', getline('.'))
bwipe!
set completeopt& wrap&
endfunc
" Check that when using feedkeys() typeahead does not interrupt searching for
" completions.
func Test_compl_feedkeys()