]> granicus.if.org Git - vim/commitdiff
patch 9.0.1371: ballooneval interferes with Insert completion v9.0.1371
authorzeertzjq <zeertzjq@outlook.com>
Thu, 2 Mar 2023 17:51:32 +0000 (17:51 +0000)
committerBram Moolenaar <Bram@vim.org>
Thu, 2 Mar 2023 17:51:32 +0000 (17:51 +0000)
Problem:    Ballooneval interferes with Insert completion.
Solution:   Ignore mouse-move events when completing. (closes #12094,
            closes #12092)

src/insexpand.c
src/testdir/test_ins_complete.vim
src/version.c

index 1362781ec34cbd1f825588ecd07b8658347ceb5f..2737f2b51f182e8b3dc0f08e1421854e83c600b1 100644 (file)
@@ -2333,9 +2333,9 @@ ins_compl_prep(int c)
     if (c != Ctrl_R && vim_is_ctrl_x_key(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_MOUSELEFT || c == K_MOUSERIGHT || c == K_MOUSEMOVE
            || c == K_COMMAND || c == K_SCRIPT_COMMAND)
        return retval;
 
@@ -3491,7 +3491,7 @@ get_next_spell_completion(linenr_T lnum UNUSED)
  * "cur_match_pos" for completion.  The length of the match is set in "len".
  */
     static char_u *
-ins_comp_get_next_word_or_line(
+ins_compl_get_next_word_or_line(
        buf_T   *ins_buf,               // buffer being scanned
        pos_T   *cur_match_pos,         // current match position
        int     *match_len,
@@ -3675,8 +3675,8 @@ get_next_default_completion(ins_compl_next_state_T *st, pos_T *start_pos)
                && start_pos->col  == st->cur_match_pos->col)
            continue;
 
-       ptr = ins_comp_get_next_word_or_line(st->ins_buf, st->cur_match_pos,
-                                                       &len, &cont_s_ipos);
+       ptr = ins_compl_get_next_word_or_line(st->ins_buf, st->cur_match_pos,
+                                                          &len, &cont_s_ipos);
        if (ptr == NULL)
            continue;
 
index fc7e8cb0edf8b0c37ef111fbd58b9f47dbf1f8ef..20dd55676ab2d0003d5c1d30fd423dfeccc7d3d8 100644 (file)
@@ -412,6 +412,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()
index 857c1394ca6f845bc1609589a83d90e9fd5e87bf..56739e7630291305ad85b3fb2f003d7b02525766 100644 (file)
@@ -695,6 +695,8 @@ static char *(features[]) =
 
 static int included_patches[] =
 {   /* Add new patch number below this line */
+/**/
+    1371,
 /**/
     1370,
 /**/