diff options
Diffstat (limited to 'src/nvim/edit.c')
-rw-r--r-- | src/nvim/edit.c | 69 |
1 files changed, 42 insertions, 27 deletions
diff --git a/src/nvim/edit.c b/src/nvim/edit.c index f3e2663d76..c20758cb0b 100644 --- a/src/nvim/edit.c +++ b/src/nvim/edit.c @@ -138,6 +138,7 @@ struct compl_S { static compl_T *compl_first_match = NULL; static compl_T *compl_curr_match = NULL; static compl_T *compl_shown_match = NULL; +static compl_T *compl_old_match = NULL; /* After using a cursor key <Enter> selects a match in the popup menu, * otherwise it inserts a line break. */ @@ -658,7 +659,7 @@ static int insert_execute(VimState *state, int key) char_u *p; if (str != NULL) { - for (p = str; *p != NUL; mb_ptr_adv(p)) { + for (p = str; *p != NUL; MB_PTR_ADV(p)) { ins_compl_addleader(PTR2CHAR(p)); } xfree(str); @@ -1196,7 +1197,7 @@ normalchar: if (str != NULL) { if (*str != NUL && stop_arrow() != FAIL) { // Insert the new value of v:char literally. - for (p = str; *p != NUL; mb_ptr_adv(p)) { + for (p = str; *p != NUL; MB_PTR_ADV(p)) { s->c = PTR2CHAR(p); if (s->c == CAR || s->c == K_KENTER || s->c == NL) { ins_eol(s->c); @@ -2008,8 +2009,8 @@ int ins_compl_add_infercase(char_u *str, int len, int icase, char_u *fname, int const char_u *p = str; actual_len = 0; while (*p != NUL) { - mb_ptr_adv(p); - ++actual_len; + MB_PTR_ADV(p); + actual_len++; } } else actual_len = len; @@ -2019,8 +2020,8 @@ int ins_compl_add_infercase(char_u *str, int len, int icase, char_u *fname, int const char_u *p = compl_orig_text; actual_compl_length = 0; while (*p != NUL) { - mb_ptr_adv(p); - ++actual_compl_length; + MB_PTR_ADV(p); + actual_compl_length++; } } else actual_compl_length = compl_length; @@ -2322,8 +2323,8 @@ static void ins_compl_longest_match(compl_T *match) break; } if (has_mbyte) { - mb_ptr_adv(p); - mb_ptr_adv(s); + MB_PTR_ADV(p); + MB_PTR_ADV(s); } else { ++p; ++s; @@ -2935,6 +2936,7 @@ static void ins_compl_free(void) } while (compl_curr_match != NULL && compl_curr_match != compl_first_match); compl_first_match = compl_curr_match = NULL; compl_shown_match = NULL; + compl_old_match = NULL; } static void ins_compl_clear(void) @@ -2974,7 +2976,7 @@ static int ins_compl_bs(void) line = get_cursor_line_ptr(); p = line + curwin->w_cursor.col; - mb_ptr_back(line, p); + MB_PTR_BACK(line, p); // Stop completion when the whole word was deleted. For Omni completion // allow the word to be deleted, we won't match everything. @@ -3440,8 +3442,9 @@ static void ins_compl_fixRedoBufForLeader(char_u *ptr_arg) ; if (len > 0) len -= (*mb_head_off)(p, p + len); - for (p += len; *p != NUL; mb_ptr_adv(p)) + for (p += len; *p != NUL; MB_PTR_ADV(p)) { AppendCharToRedobuff(K_BS); + } } else { len = 0; } @@ -3671,7 +3674,6 @@ static int ins_compl_get_exp(pos_T *ini) char_u *ptr; char_u *dict = NULL; int dict_f = 0; - compl_T *old_match; int set_match_pos; int l_ctrl_x_mode = ctrl_x_mode; @@ -3686,7 +3688,7 @@ static int ins_compl_get_exp(pos_T *ini) last_match_pos = first_match_pos = *ini; } - old_match = compl_curr_match; /* remember the last current match */ + compl_old_match = compl_curr_match; // remember the last current match pos = (compl_direction == FORWARD) ? &last_match_pos : &first_match_pos; /* For ^N/^P loop over all the flags/windows/buffers in 'complete' */ for (;; ) { @@ -3775,6 +3777,12 @@ static int ins_compl_get_exp(pos_T *ini) } } + // If complete() was called then compl_pattern has been reset. + // The following won't work then, bail out. + if (compl_pattern == NULL) { + break; + } + switch (type) { case -1: break; @@ -3981,10 +3989,11 @@ static int ins_compl_get_exp(pos_T *ini) p_ws = save_p_ws; } - /* check if compl_curr_match has changed, (e.g. other type of - * expansion added something) */ - if (type != 0 && compl_curr_match != old_match) + // check if compl_curr_match has changed, (e.g. other type of + // expansion added something) + if (type != 0 && compl_curr_match != compl_old_match) { found_new_match = OK; + } /* break the loop for specialized modes (use 'complete' just for the * generic l_ctrl_x_mode == 0) or when we've found a new match */ @@ -4024,13 +4033,17 @@ static int ins_compl_get_exp(pos_T *ini) i = ins_compl_make_cyclic(); } - /* If several matches were added (FORWARD) or the search failed and has - * just been made cyclic then we have to move compl_curr_match to the next - * or previous entry (if any) -- Acevedo */ - compl_curr_match = compl_direction == FORWARD ? old_match->cp_next - : old_match->cp_prev; - if (compl_curr_match == NULL) - compl_curr_match = old_match; + if (compl_old_match != NULL) { + // If several matches were added (FORWARD) or the search failed and has + // just been made cyclic then we have to move compl_curr_match to the + // next or previous entry (if any) -- Acevedo + compl_curr_match = compl_direction == FORWARD + ? compl_old_match->cp_next + : compl_old_match->cp_prev; + if (compl_curr_match == NULL) { + compl_curr_match = compl_old_match; + } + } return i; } @@ -4597,13 +4610,15 @@ static int ins_complete(int c, bool enable_pum) if (startcol > 0) { char_u *p = line + startcol; - mb_ptr_back(line, p); - while (p > line && vim_isfilec(PTR2CHAR(p))) - mb_ptr_back(line, p); - if (p == line && vim_isfilec(PTR2CHAR(p))) + MB_PTR_BACK(line, p); + while (p > line && vim_isfilec(PTR2CHAR(p))) { + MB_PTR_BACK(line, p); + } + if (p == line && vim_isfilec(PTR2CHAR(p))) { startcol = 0; - else + } else { startcol = (int)(p - line) + 1; + } } compl_col += startcol; |