vim-patch:9.1.1197: process_next_cpt_value() uses wrong condition

Problem:  process_next_cpt_value() uses wrong condition
Solution: use cfc_has_mode() instead and remove redundant else if branch
          (glepnir)

closes: vim/vim#16833

53b14578e0

Co-authored-by: glepnir <glephunter@gmail.com>
This commit is contained in:
zeertzjq
2025-03-13 07:08:25 +08:00
parent cd95ea5d48
commit 28f6199474
6 changed files with 69 additions and 35 deletions

View File

@@ -1520,14 +1520,23 @@ A jump table for the options with a short description can be found at |Q_op|.
*'completefuzzycollect'* *'cfc'* *'completefuzzycollect'* *'cfc'*
'completefuzzycollect' 'cfc' string (default "") 'completefuzzycollect' 'cfc' string (default "")
global global
This option enables fuzzy collection for (only some) specific A comma-separated list of option enables fuzzy collection for specific
|ins-completion| modes, adjusting how items are gathered for fuzzy |ins-completion| modes, affecting how items are gathered during
matching based on input. completion. When set, fuzzy matching is used to find completion
The option can contain the following values (separated by commas), candidates instead of the standard prefix-based matching. This option
each enabling fuzzy collection for a specific completion mode: can contain the following values are:
files file names
keyword keyword completion in 'complete' and current file keyword keywords in the current file |i_CTRL-X_CTRL-N|
whole_line whole lines keywords with the ".", "w", "b", "u", "U" and
"k{dict}" flags in 'complete'. |i_CTRL-N| |i_CTRL-P|
files file names |i_CTRL-X_CTRL-F|
whole_line whole lines |i_CTRL-X_CTRL-L|
When used with 'completeopt' "longest" option, fuzzy collection can
identify the longest common string among the best fuzzy matches and
automatically insert it.
*'completeitemalign'* *'cia'* *'completeitemalign'* *'cia'*
'completeitemalign' 'cia' string (default "abbr,kind,menu") 'completeitemalign' 'cia' string (default "abbr,kind,menu")

View File

@@ -1044,14 +1044,23 @@ vim.o.cfu = vim.o.completefunc
vim.bo.completefunc = vim.o.completefunc vim.bo.completefunc = vim.o.completefunc
vim.bo.cfu = vim.bo.completefunc vim.bo.cfu = vim.bo.completefunc
--- This option enables fuzzy collection for (only some) specific --- A comma-separated list of option enables fuzzy collection for specific
--- `ins-completion` modes, adjusting how items are gathered for fuzzy --- `ins-completion` modes, affecting how items are gathered during
--- matching based on input. --- completion. When set, fuzzy matching is used to find completion
--- The option can contain the following values (separated by commas), --- candidates instead of the standard prefix-based matching. This option
--- each enabling fuzzy collection for a specific completion mode: --- can contain the following values are:
--- files file names ---
--- keyword keyword completion in 'complete' and current file --- keyword keywords in the current file `i_CTRL-X_CTRL-N`
--- whole_line whole lines --- keywords with the ".", "w", "b", "u", "U" and
--- "k{dict}" flags in 'complete'. `i_CTRL-N` `i_CTRL-P`
---
--- files file names `i_CTRL-X_CTRL-F`
---
--- whole_line whole lines `i_CTRL-X_CTRL-L`
---
--- When used with 'completeopt' "longest" option, fuzzy collection can
--- identify the longest common string among the best fuzzy matches and
--- automatically insert it.
--- ---
--- @type string --- @type string
vim.o.completefuzzycollect = "" vim.o.completefuzzycollect = ""

View File

@@ -3219,7 +3219,7 @@ enum {
/// the "st->e_cpt" option value and process the next matching source. /// the "st->e_cpt" option value and process the next matching source.
/// INS_COMPL_CPT_END if all the values in "st->e_cpt" are processed. /// INS_COMPL_CPT_END if all the values in "st->e_cpt" are processed.
static int process_next_cpt_value(ins_compl_next_state_T *st, int *compl_type_arg, static int process_next_cpt_value(ins_compl_next_state_T *st, int *compl_type_arg,
pos_T *start_match_pos, bool in_fuzzy) pos_T *start_match_pos, bool fuzzy_collect)
{ {
int compl_type = -1; int compl_type = -1;
int status = INS_COMPL_CPT_OK; int status = INS_COMPL_CPT_OK;
@@ -3235,7 +3235,7 @@ static int process_next_cpt_value(ins_compl_next_state_T *st, int *compl_type_ar
st->first_match_pos = *start_match_pos; st->first_match_pos = *start_match_pos;
// Move the cursor back one character so that ^N can match the // Move the cursor back one character so that ^N can match the
// word immediately after the cursor. // word immediately after the cursor.
if (ctrl_x_mode_normal() && (!in_fuzzy && dec(&st->first_match_pos) < 0)) { if (ctrl_x_mode_normal() && (!fuzzy_collect && dec(&st->first_match_pos) < 0)) {
// Move the cursor to after the last character in the // Move the cursor to after the last character in the
// buffer, so that word at start of buffer is found // buffer, so that word at start of buffer is found
// correctly. // correctly.
@@ -3924,7 +3924,6 @@ static int ins_compl_get_exp(pos_T *ini)
static bool st_cleared = false; static bool st_cleared = false;
int found_new_match; int found_new_match;
int type = ctrl_x_mode; int type = ctrl_x_mode;
bool in_fuzzy = (get_cot_flags() & kOptCotFlagFuzzy) != 0;
assert(curbuf != NULL); assert(curbuf != NULL);
@@ -3961,7 +3960,7 @@ static int ins_compl_get_exp(pos_T *ini)
// entries from 'complete' that look in loaded buffers. // entries from 'complete' that look in loaded buffers.
if ((ctrl_x_mode_normal() || ctrl_x_mode_line_or_eval()) if ((ctrl_x_mode_normal() || ctrl_x_mode_line_or_eval())
&& (!compl_started || st.found_all)) { && (!compl_started || st.found_all)) {
int status = process_next_cpt_value(&st, &type, ini, in_fuzzy); int status = process_next_cpt_value(&st, &type, ini, cfc_has_mode());
if (status == INS_COMPL_CPT_END) { if (status == INS_COMPL_CPT_END) {
break; break;
} }

View File

@@ -1466,14 +1466,23 @@ local options = {
flags = true, flags = true,
deny_duplicates = true, deny_duplicates = true,
desc = [=[ desc = [=[
This option enables fuzzy collection for (only some) specific A comma-separated list of option enables fuzzy collection for specific
|ins-completion| modes, adjusting how items are gathered for fuzzy |ins-completion| modes, affecting how items are gathered during
matching based on input. completion. When set, fuzzy matching is used to find completion
The option can contain the following values (separated by commas), candidates instead of the standard prefix-based matching. This option
each enabling fuzzy collection for a specific completion mode: can contain the following values are:
files file names
keyword keyword completion in 'complete' and current file keyword keywords in the current file |i_CTRL-X_CTRL-N|
whole_line whole lines keywords with the ".", "w", "b", "u", "U" and
"k{dict}" flags in 'complete'. |i_CTRL-N| |i_CTRL-P|
files file names |i_CTRL-X_CTRL-F|
whole_line whole lines |i_CTRL-X_CTRL-L|
When used with 'completeopt' "longest" option, fuzzy collection can
identify the longest common string among the best fuzzy matches and
automatically insert it.
]=], ]=],
full_name = 'completefuzzycollect', full_name = 'completefuzzycollect',
list = 'onecomma', list = 'onecomma',

View File

@@ -3629,7 +3629,7 @@ garray_T *fuzzy_match_str_with_pos(char *const str, const char *const pat)
/// - `*len` is set to the length of the matched word. /// - `*len` is set to the length of the matched word.
/// - `*score` contains the match score. /// - `*score` contains the match score.
/// ///
/// If no match is found, `*ptr` is updated to to the end of the line. /// If no match is found, `*ptr` is updated to the end of the line.
bool fuzzy_match_str_in_line(char **ptr, char *pat, int *len, pos_T *current_pos, int *score) bool fuzzy_match_str_in_line(char **ptr, char *pat, int *len, pos_T *current_pos, int *score)
{ {
char *str = *ptr; char *str = *ptr;
@@ -3699,9 +3699,6 @@ bool search_for_fuzzy_match(buf_T *buf, pos_T *pos, char *pattern, int dir, pos_
bool looped_around = false; bool looped_around = false;
bool whole_line = ctrl_x_mode_whole_line(); bool whole_line = ctrl_x_mode_whole_line();
if (whole_line) {
current_pos.lnum += dir;
}
if (buf == curbuf) { if (buf == curbuf) {
circly_end = *start_pos; circly_end = *start_pos;
@@ -3711,6 +3708,10 @@ bool search_for_fuzzy_match(buf_T *buf, pos_T *pos, char *pattern, int dir, pos_
circly_end.coladd = 0; circly_end.coladd = 0;
} }
if (whole_line && start_pos->lnum != pos->lnum) {
current_pos.lnum += dir;
}
while (true) { while (true) {
// Check if looped around and back to start position // Check if looped around and back to start position
if (looped_around && equalpos(current_pos, circly_end)) { if (looped_around && equalpos(current_pos, circly_end)) {
@@ -3721,11 +3722,14 @@ bool search_for_fuzzy_match(buf_T *buf, pos_T *pos, char *pattern, int dir, pos_
if (current_pos.lnum >= 1 && current_pos.lnum <= buf->b_ml.ml_line_count) { if (current_pos.lnum >= 1 && current_pos.lnum <= buf->b_ml.ml_line_count) {
// Get the current line buffer // Get the current line buffer
*ptr = ml_get_buf(buf, current_pos.lnum); *ptr = ml_get_buf(buf, current_pos.lnum);
if (!whole_line) {
*ptr += current_pos.col;
}
// If ptr is end of line is reached, move to next line // If ptr is end of line is reached, move to next line
// or previous line based on direction // or previous line based on direction
if (*ptr != NULL && **ptr != NUL) { if (*ptr != NULL && **ptr != NUL) {
if (!whole_line) { if (!whole_line) {
*ptr += current_pos.col;
// Try to find a fuzzy match in the current line starting // Try to find a fuzzy match in the current line starting
// from current position // from current position
found_new_match = fuzzy_match_str_in_line(ptr, pattern, found_new_match = fuzzy_match_str_in_line(ptr, pattern,
@@ -3743,8 +3747,6 @@ bool search_for_fuzzy_match(buf_T *buf, pos_T *pos, char *pattern, int dir, pos_
} }
next_word_end += l; next_word_end += l;
} }
} else if (looped_around) {
found_new_match = false;
} }
*len = (int)(next_word_end - *ptr); *len = (int)(next_word_end - *ptr);
current_pos.col = *len; current_pos.col = *len;

View File

@@ -2982,6 +2982,12 @@ func Test_complete_fuzzy_collect()
call feedkeys("STe\<C-X>\<C-N>x\<CR>\<Esc>0", 'tx!') call feedkeys("STe\<C-X>\<C-N>x\<CR>\<Esc>0", 'tx!')
call assert_equal('Tex', getline(line('.') - 1)) call assert_equal('Tex', getline(line('.') - 1))
call setline(1, ['fuzzy', 'fuzzycollect', 'completefuzzycollect'])
call feedkeys("Gofuzzy\<C-X>\<C-N>\<C-N>\<C-N>\<CR>\<Esc>0", 'tx!')
call assert_equal('fuzzycollect', getline(line('.') - 1))
call feedkeys("Gofuzzy\<C-X>\<C-N>\<C-N>\<C-N>\<C-N>\<CR>\<Esc>0", 'tx!')
call assert_equal('completefuzzycollect', getline(line('.') - 1))
bw! bw!
bw! bw!
set completeopt& cfc& cpt& set completeopt& cfc& cpt&