Patch 8.2.3293
Problem:    Finding completions may cause an endless loop.
Solution:   Use a better way to check coming back where the search started.
            (Andy Gozas, closes #8672, closes #8671)
Files:      src/insexpand.c, src/testdir/Make_all.mak,
            src/testdir/test_ins_complete_no_halt.vim


*** ../vim-8.2.3292/src/insexpand.c     2021-07-27 22:00:39.745712396 +0200
--- src/insexpand.c     2021-08-05 16:20:14.903411222 +0200
***************
*** 2712,2717 ****
--- 2712,2719 ----
      char_u    *dict = NULL;
      int               dict_f = 0;
      int               set_match_pos;
+     pos_T     prev_pos = {0, 0, 0};
+     int               looped_around = FALSE;
  
      if (!compl_started)
      {
***************
*** 2964,2969 ****
--- 2966,2972 ----
                p_ws = FALSE;
            else if (*e_cpt == '.')
                p_ws = TRUE;
+           looped_around = FALSE;
            for (;;)
            {
                int     cont_s_ipos = FALSE;
***************
*** 2991,2998 ****
                    set_match_pos = FALSE;
                }
                else if (first_match_pos.lnum == last_match_pos.lnum
!                                && first_match_pos.col == last_match_pos.col)
                    found_new_match = FAIL;
                if (found_new_match == FAIL)
                {
                    if (ins_buf == curbuf)
--- 2994,3024 ----
                    set_match_pos = FALSE;
                }
                else if (first_match_pos.lnum == last_match_pos.lnum
!                                 && first_match_pos.col == last_match_pos.col)
!               {
                    found_new_match = FAIL;
+               }
+               else if ((compl_direction == FORWARD)
+                       && (prev_pos.lnum > pos->lnum
+                           || (prev_pos.lnum == pos->lnum
+                               && prev_pos.col >= pos->col)))
+               {
+                   if (looped_around)
+                       found_new_match = FAIL;
+                   else
+                       looped_around = TRUE;
+               }
+               else if ((compl_direction != FORWARD)
+                       && (prev_pos.lnum < pos->lnum
+                           || (prev_pos.lnum == pos->lnum
+                               && prev_pos.col <= pos->col)))
+               {
+                   if (looped_around)
+                       found_new_match = FAIL;
+                   else
+                       looped_around = TRUE;
+               }
+               prev_pos = *pos;
                if (found_new_match == FAIL)
                {
                    if (ins_buf == curbuf)
*** ../vim-8.2.3292/src/testdir/Make_all.mak    2021-06-27 12:07:12.444471041 
+0200
--- src/testdir/Make_all.mak    2021-08-05 16:20:51.155297920 +0200
***************
*** 162,167 ****
--- 162,168 ----
        test_increment_dbcs \
        test_indent \
        test_ins_complete \
+       test_ins_complete_no_halt \
        test_interrupt \
        test_job_fails \
        test_join \
***************
*** 405,410 ****
--- 406,412 ----
        test_increment_dbcs.res \
        test_indent.res \
        test_ins_complete.res \
+       test_ins_complete_no_halt.res \
        test_interrupt.res \
        test_job_fails.res \
        test_join.res \
*** ../vim-8.2.3292/src/testdir/test_ins_complete_no_halt.vim   2021-08-05 
16:22:52.298929361 +0200
--- src/testdir/test_ins_complete_no_halt.vim   2021-08-05 16:22:24.467012774 
+0200
***************
*** 0 ****
--- 1,51 ----
+ " Test insert mode completion does not get stuck when looping around.
+ " In a separate file to avoid the settings to leak to other test cases.
+ 
+ set complete+=kspell
+ set completeopt+=menu
+ set completeopt+=menuone
+ set completeopt+=noselect
+ set completeopt+=noinsert
+ let g:autocompletion = v:true
+ 
+ func Test_ins_complete_no_halt()
+   function! OpenCompletion()
+     if pumvisible() && (g:autocompletion == v:true)
+       call feedkeys("\<C-e>\<C-n>", "i")
+       return
+     endif
+     if ((v:char >= 'a' && v:char <= 'z') || (v:char >= 'A' && v:char <= 'Z')) 
&& (g:autocompletion == v:true)
+       call feedkeys("\<C-n>", "i")
+       redraw
+     endif
+   endfunction
+ 
+   autocmd InsertCharPre * noautocmd call OpenCompletion()
+ 
+   setlocal spell! spelllang=en_us
+ 
+   call feedkeys("iauto-complete-halt-test test test test test test test test 
test test test test test test test test test test test\<C-c>", "tx!")
+   call assert_equal(["auto-complete-halt-test test test test test test test 
test test test test test test test test test test test test"], getline(1, "$"))
+ endfunc
+ 
+ func Test_auto_complete_backwards_no_halt()
+   function! OpenCompletion()
+     if pumvisible() && (g:autocompletion == v:true)
+       call feedkeys("\<C-e>\<C-p>", "i")
+       return
+     endif
+     if ((v:char >= 'a' && v:char <= 'z') || (v:char >= 'A' && v:char <= 'Z')) 
&& (g:autocompletion == v:true)
+       call feedkeys("\<C-p>", "i")
+       redraw
+     endif
+   endfunction
+ 
+   autocmd InsertCharPre * noautocmd call OpenCompletion()
+ 
+   setlocal spell! spelllang=en_us
+ 
+   call feedkeys("iauto-complete-halt-test test test test test test test test 
test test test test test test test test test test test\<C-c>", "tx!")
+   call assert_equal(["auto-complete-halt-test test test test test test test 
test test test test test test test test test test test test"], getline(1, "$"))
+ endfunc
+ 
+ " vim: shiftwidth=2 sts=2 expandtab
*** ../vim-8.2.3292/src/version.c       2021-08-05 15:24:55.739550482 +0200
--- src/version.c       2021-08-05 16:00:00.671500077 +0200
***************
*** 757,758 ****
--- 757,760 ----
  {   /* Add new patch number below this line */
+ /**/
+     3293,
  /**/

-- 
GUARD #2:  Wait a minute -- supposing two swallows carried it together?
GUARD #1:  No, they'd have to have it on a line.
GUARD #2:  Well, simple!  They'd just use a standard creeper!
GUARD #1:  What, held under the dorsal guiding feathers?
GUARD #2:  Well, why not?
                                  The Quest for the Holy Grail (Monty Python)

 /// Bram Moolenaar -- [email protected] -- http://www.Moolenaar.net   \\\
///                                                                      \\\
\\\        sponsor Vim, vote for features -- http://www.Vim.org/sponsor/ ///
 \\\            help me help AIDS victims -- http://ICCF-Holland.org    ///

-- 
-- 
You received this message from the "vim_dev" maillist.
Do not top-post! Type your reply below the text you are replying to.
For more information, visit http://www.vim.org/maillist.php

--- 
You received this message because you are subscribed to the Google Groups 
"vim_dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/vim_dev/202108051423.175ENtTW1314794%40masaka.moolenaar.net.

Raspunde prin e-mail lui