]> git.ipfire.org Git - thirdparty/vim.git/commitdiff
patch 9.1.1475: completion: regression when "nearest" in 'completeopt' v9.1.1475
authorGirish Palya <girishji@gmail.com>
Sun, 22 Jun 2025 18:23:54 +0000 (20:23 +0200)
committerChristian Brabandt <cb@256bit.org>
Sun, 22 Jun 2025 18:23:54 +0000 (20:23 +0200)
Problem:  completion: regression when "nearest" in 'completeopt'
Solution: fix compare function (Girish Palya)

closes: #17577

Signed-off-by: Girish Palya <girishji@gmail.com>
Signed-off-by: Christian Brabandt <cb@256bit.org>
src/insexpand.c
src/testdir/test_ins_complete.vim
src/version.c

index 94eb760d7e29c81d0b7d5cd3345fe2a7ab44f09d..ed1b5ff292914232699e6268b4125faf8e02b8a4 100644 (file)
@@ -1404,7 +1404,7 @@ cp_compare_nearest(const void* a, const void* b)
 {
     int score_a = ((compl_T*)a)->cp_score;
     int score_b = ((compl_T*)b)->cp_score;
-    if (score_a < 0 || score_b < 0)
+    if (score_a == 0 || score_b == 0)
        return 0;
     return (score_a > score_b) ? 1 : (score_a < score_b) ? -1 : 0;
 }
index df59e1e2a009713f2684145597bb7a9f91439820..b6692b55423c7c15363eccda56aaaaaa05870fb9 100644 (file)
@@ -4492,6 +4492,22 @@ func Test_nearest_cpt_option()
   exe "normal! of\<c-n>\<c-r>=PrintMenuWords()\<cr>"
   call assert_equal('f{''matches'': [''foo1'', ''foo3'', ''foo2''], ''selected'': -1}', getline(2))
 
+  " Multiple sources
+  func F1(findstart, base)
+    if a:findstart
+      return col('.') - 1
+    endif
+    return ['foo4', 'foo5']
+  endfunc
+  %d
+  set complete+=FF1
+  call setline(1, ["foo1", "foo2", "bar1", "foo3"])
+  exe "normal! 2jof\<c-n>\<c-r>=PrintMenuWords()\<cr>"
+  call assert_equal('f{''matches'': [''foo3'', ''foo2'', ''foo1'', ''foo4'', ''foo5''],
+        \ ''selected'': -1}', getline(4))
+  set complete-=FF1
+  delfunc F1
+
   set completeopt=menu,longest,nearest
   %d
   call setline(1, ["fo", "foo", "foobar", "foobarbaz"])
index 8f9033bf72f8098e300598f53cbab2264d8679e5..f8dc4084b6b186c58ad51322471d23d1a906c58c 100644 (file)
@@ -709,6 +709,8 @@ static char *(features[]) =
 
 static int included_patches[] =
 {   /* Add new patch number below this line */
+/**/
+    1475,
 /**/
     1474,
 /**/