Merge pull request #34294 from glepnir/vim-9.1.1426

vim-patch:9.1.{1426,1428}: register completion improve
This commit is contained in:
zeertzjq
2025-06-04 13:46:19 +08:00
committed by GitHub
6 changed files with 85 additions and 26 deletions

View File

@@ -4193,6 +4193,7 @@ static int get_next_default_completion(ins_compl_next_state_T *st, pos_T *start_
static void get_register_completion(void)
{
Direction dir = compl_direction;
bool adding_mode = compl_status_adding();
for (int i = 0; i < NUM_REGISTERS; i++) {
int regname = get_register_name(i);
@@ -4215,28 +4216,62 @@ static void get_register_completion(void)
continue;
}
char *p = str;
while (*p != NUL) {
p = find_word_start(p);
if (*p == NUL) {
break;
if (adding_mode) {
int str_len = (int)strlen(str);
if (str_len == 0) {
continue;
}
char *word_end = find_word_end(p);
int len = (int)(word_end - p);
// Add the word to the completion list
if (len > 0 && (!compl_orig_text.data
|| (p_ic ? STRNICMP(p, compl_orig_text.data,
compl_orig_text.size) == 0
: strncmp(p, compl_orig_text.data,
compl_orig_text.size) == 0))) {
if (ins_compl_add_infercase(p, len, p_ic, NULL,
dir, false, 0) == OK) {
if (!compl_orig_text.data
|| (p_ic ? STRNICMP(str, compl_orig_text.data,
compl_orig_text.size) == 0
: strncmp(str, compl_orig_text.data,
compl_orig_text.size) == 0)) {
if (ins_compl_add_infercase(str, str_len, p_ic, NULL, dir, false, 0) == OK) {
dir = FORWARD;
}
}
p = word_end;
} else {
// Calculate the safe end of string to avoid null byte issues
char *str_end = str + strlen(str);
char *p = str;
// Safely iterate through the string
while (p < str_end && *p != NUL) {
char *old_p = p;
p = find_word_start(p);
if (p >= str_end || *p == NUL) {
break;
}
char *word_end = find_word_end(p);
if (word_end <= p) {
word_end = p + utfc_ptr2len(p);
}
if (word_end > str_end) {
word_end = str_end;
}
int len = (int)(word_end - p);
if (len > 0 && (!compl_orig_text.data
|| (p_ic ? STRNICMP(p, compl_orig_text.data,
compl_orig_text.size) == 0
: strncmp(p, compl_orig_text.data,
compl_orig_text.size) == 0))) {
if (ins_compl_add_infercase(p, len, p_ic, NULL,
dir, false, 0) == OK) {
dir = FORWARD;
}
}
p = word_end;
if (p <= old_p) {
p = old_p + utfc_ptr2len(old_p);
}
}
}
}
@@ -5468,7 +5503,7 @@ static int get_spell_compl_info(int startcol, colnr_T curs_col)
/// @return OK on success.
static int compl_get_info(char *line, int startcol, colnr_T curs_col, bool *line_invalid)
{
if (ctrl_x_mode_normal()
if (ctrl_x_mode_normal() || ctrl_x_mode_register()
|| ((ctrl_x_mode & CTRL_X_WANT_IDENT)
&& !thesaurus_func_complete(ctrl_x_mode))) {
return get_normal_compl_info(line, startcol, curs_col);
@@ -5489,8 +5524,6 @@ static int compl_get_info(char *line, int startcol, colnr_T curs_col, bool *line
return FAIL;
}
*line_invalid = true; // "line" may have become invalid
} else if (ctrl_x_mode_register()) {
return get_normal_compl_info(line, startcol, curs_col);
} else {
internal_error("ins_complete()");
return FAIL;
@@ -5546,7 +5579,7 @@ static void ins_compl_continue_search(char *line)
if (compl_length < 1) {
compl_cont_status &= CONT_LOCAL;
}
} else if (ctrl_x_mode_line_or_eval()) {
} else if (ctrl_x_mode_line_or_eval() || ctrl_x_mode_register()) {
compl_cont_status = CONT_ADDING | CONT_N_ADDS;
} else {
compl_cont_status = 0;