From b53ba9d9a7af93f34aee92b32a9ccd478c4092d6 Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Sun, 1 Sep 2024 06:22:37 +0800 Subject: [PATCH] vim-patch:9.1.0705: Sorting of fuzzy filename completion is not stable Problem: Sorting of fuzzy filename completion is not stable Solution: Compare indexes when scores are equal. Fix some typos. (zeertzjq) closes: vim/vim#15593 https://github.com/vim/vim/commit/58d705238c0794ee3baa4173831ab157e709a48a --- src/nvim/insexpand.c | 3 ++- test/functional/ui/popupmenu_spec.lua | 4 ++-- test/old/testdir/test_popup.vim | 2 +- 3 files changed, 5 insertions(+), 4 deletions(-) diff --git a/src/nvim/insexpand.c b/src/nvim/insexpand.c index 15953fc93f..b375d11385 100644 --- a/src/nvim/insexpand.c +++ b/src/nvim/insexpand.c @@ -3171,7 +3171,8 @@ static int compare_scores(const void *a, const void *b) int idx_b = *(const int *)b; int score_a = compl_fuzzy_scores[idx_a]; int score_b = compl_fuzzy_scores[idx_b]; - return (score_a > score_b) ? -1 : (score_a < score_b) ? 1 : 0; + return score_a == score_b ? (idx_a == idx_b ? 0 : (idx_a < idx_b ? -1 : 1)) + : (score_a > score_b ? -1 : 1); } /// Get the next set of filename matching "compl_pattern". diff --git a/test/functional/ui/popupmenu_spec.lua b/test/functional/ui/popupmenu_spec.lua index eb9b0f1cc1..c5c75fa010 100644 --- a/test/functional/ui/popupmenu_spec.lua +++ b/test/functional/ui/popupmenu_spec.lua @@ -5311,9 +5311,9 @@ describe('builtin popupmenu', function() {2:-- }{5:match 2 of 3} | ]]) - feed('S/non_exit_folder') + feed('S/non_existing_folder') screen:expect([[ - /non_exit_folder^ | + /non_existing_folder^ | {1:~ }|*18 {2:-- }{6:Pattern not found} | ]]) diff --git a/test/old/testdir/test_popup.vim b/test/old/testdir/test_popup.vim index 58b7c4147f..95b5b5d595 100644 --- a/test/old/testdir/test_popup.vim +++ b/test/old/testdir/test_popup.vim @@ -1514,7 +1514,7 @@ func Test_pum_highlights_match() call VerifyScreenDump(buf, 'Test_pum_highlights_11', {}) " issue #15357 - call term_sendkeys(buf, "\S/non_exit_folder\\") + call term_sendkeys(buf, "\S/non_existing_folder\\") call TermWait(buf, 50) call VerifyScreenDump(buf, 'Test_pum_highlights_15', {})