diff options
-rw-r--r-- | src/nvim/edit.c | 118 | ||||
-rw-r--r-- | src/nvim/search.c | 15 | ||||
-rw-r--r-- | src/nvim/spell.c | 9 | ||||
-rw-r--r-- | src/nvim/spell.h | 1 | ||||
-rw-r--r-- | src/nvim/testdir/test_ins_complete.vim | 2 |
5 files changed, 81 insertions, 64 deletions
diff --git a/src/nvim/edit.c b/src/nvim/edit.c index d6668439c5..7fefa8520a 100644 --- a/src/nvim/edit.c +++ b/src/nvim/edit.c @@ -196,8 +196,8 @@ static int ctrl_x_mode = CTRL_X_NORMAL; static int compl_matches = 0; static char_u *compl_pattern = NULL; -static int compl_direction = FORWARD; -static int compl_shows_dir = FORWARD; +static Direction compl_direction = FORWARD; +static Direction compl_shows_dir = FORWARD; static int compl_pending = 0; // > 1 for postponed CTRL-N static pos_T compl_startpos; static colnr_T compl_col = 0; /* column where the text starts @@ -2156,7 +2156,7 @@ static bool ins_compl_accept_char(int c) /// /// @param[in] cont_s_ipos next ^X<> will set initial_pos int ins_compl_add_infercase(char_u *str_arg, int len, bool icase, char_u *fname, - int dir, bool cont_s_ipos) + Direction dir, bool cont_s_ipos) FUNC_ATTR_NONNULL_ARG(1) { char_u *str = str_arg; @@ -2308,7 +2308,7 @@ static int ins_compl_add(char_u *const str, int len, FUNC_ATTR_NONNULL_ARG(1) { compl_T *match; - int dir = (cdir == kDirectionNotSet ? compl_direction : cdir); + const Direction dir = (cdir == kDirectionNotSet ? compl_direction : cdir); int flags = flags_arg; os_breakcheck(); @@ -2511,7 +2511,7 @@ static void ins_compl_add_matches(int num_matches, char_u **matches, int icase) FUNC_ATTR_NONNULL_ALL { int add_r = OK; - int dir = compl_direction; + Direction dir = compl_direction; for (int i = 0; i < num_matches && add_r != FAIL; i++) { if ((add_r = ins_compl_add(matches[i], -1, NULL, NULL, false, NULL, dir, @@ -2864,7 +2864,7 @@ ins_compl_dictionaries ( char_u **files; int count; int save_p_scs; - int dir = compl_direction; + Direction dir = compl_direction; if (*dict == NUL) { /* When 'dictionary' is empty and spell checking is enabled use @@ -2945,7 +2945,10 @@ theend: xfree(buf); } -static void ins_compl_files(int count, char_u **files, int thesaurus, int flags, regmatch_T *regmatch, char_u *buf, int *dir) +static void ins_compl_files(int count, char_u **files, int thesaurus, + int flags, regmatch_T *regmatch, char_u *buf, + Direction *dir) + FUNC_ATTR_NONNULL_ARG(2, 7) { char_u *ptr; int i; @@ -3137,6 +3140,56 @@ bool ins_compl_active(void) return compl_started; } +static void ins_compl_update_sequence_numbers(void) +{ + int number = 0; + compl_T *match; + + if (compl_direction == FORWARD) { + // search backwards for the first valid (!= -1) number. + // This should normally succeed already at the first loop + // cycle, so it's fast! + for (match = compl_curr_match->cp_prev; + match != NULL && match != compl_first_match; + match = match->cp_prev) { + if (match->cp_number != -1) { + number = match->cp_number; + break; + } + } + if (match != NULL) { + // go up and assign all numbers which are not assigned yet + for (match = match->cp_next; + match != NULL && match->cp_number == -1; + match = match->cp_next) { + match->cp_number = ++number; + } + } + } else { // BACKWARD + assert(compl_direction == BACKWARD); + // search forwards (upwards) for the first valid (!= -1) + // number. This should normally succeed already at the + // first loop cycle, so it's fast! + for (match = compl_curr_match->cp_next; + match != NULL && match != compl_first_match; + match = match->cp_next) { + if (match->cp_number != -1) { + number = match->cp_number; + break; + } + } + if (match != NULL) { + // go down and assign all numbers which are not + // assigned yet + for (match = match->cp_prev; + match && match->cp_number == -1; + match = match->cp_prev) { + match->cp_number = ++number; + } + } + } +} + // Get complete information void get_complete_info(list_T *what_list, dict_T *retdict) { @@ -3214,6 +3267,9 @@ void get_complete_info(list_T *what_list, dict_T *retdict) } if (ret == OK && (what_flag & CI_WHAT_SELECTED)) { + if (compl_curr_match != NULL && compl_curr_match->cp_number == -1) { + ins_compl_update_sequence_numbers(); + } ret = tv_dict_add_nr(retdict, S_LEN("selected"), (compl_curr_match != NULL) ? compl_curr_match->cp_number - 1 : -1); @@ -3865,7 +3921,7 @@ theend: */ static void ins_compl_add_list(list_T *const list) { - int dir = compl_direction; + Direction dir = compl_direction; // Go through the List with matches and add each of them. TV_LIST_ITER(list, li, { @@ -5242,53 +5298,11 @@ static int ins_complete(int c, bool enable_pum) } else if (compl_curr_match->cp_next == compl_curr_match->cp_prev) { edit_submode_extra = (char_u *)_("The only match"); edit_submode_highl = HLF_COUNT; - compl_curr_match->cp_number = 0; + compl_curr_match->cp_number = 1; } else { // Update completion sequence number when needed. if (compl_curr_match->cp_number == -1) { - int number = 0; - compl_T *match; - - if (compl_direction == FORWARD) { - /* search backwards for the first valid (!= -1) number. - * This should normally succeed already at the first loop - * cycle, so it's fast! */ - for (match = compl_curr_match->cp_prev; match != NULL - && match != compl_first_match; - match = match->cp_prev) - if (match->cp_number != -1) { - number = match->cp_number; - break; - } - if (match != NULL) - /* go up and assign all numbers which are not assigned - * yet */ - for (match = match->cp_next; - match != NULL && match->cp_number == -1; - match = match->cp_next) - match->cp_number = ++number; - } else { // BACKWARD - // search forwards (upwards) for the first valid (!= -1) - // number. This should normally succeed already at the - // first loop cycle, so it's fast! - for (match = compl_curr_match->cp_next; - match != NULL && match != compl_first_match; - match = match->cp_next) { - if (match->cp_number != -1) { - number = match->cp_number; - break; - } - } - if (match != NULL) { - // go down and assign all numbers which are not - // assigned yet - for (match = match->cp_prev; - match && match->cp_number == -1; - match = match->cp_prev) { - match->cp_number = ++number; - } - } - } + ins_compl_update_sequence_numbers(); } /* The match should always have a sequence number now, this is diff --git a/src/nvim/search.c b/src/nvim/search.c index 90e1e25de2..787a464070 100644 --- a/src/nvim/search.c +++ b/src/nvim/search.c @@ -89,7 +89,7 @@ static struct spat spats[2] = static int last_idx = 0; /* index in spats[] for RE_LAST */ static char_u lastc[2] = { NUL, NUL }; // last character searched for -static int lastcdir = FORWARD; // last direction of character search +static Direction lastcdir = FORWARD; // last direction of character search static int last_t_cmd = true; // last search t_cmd static char_u lastc_bytes[MB_MAXBYTES + 1]; static int lastc_bytelen = 1; // >1 for multi-byte char @@ -437,7 +437,7 @@ void set_last_csearch(int c, char_u *s, int len) memset(lastc_bytes, 0, sizeof(lastc_bytes)); } -void set_csearch_direction(int cdir) +void set_csearch_direction(Direction cdir) { lastcdir = cdir; } @@ -1430,7 +1430,7 @@ end_do_search: * ADDING is set. If p_ic is set then the pattern must be in lowercase. * Return OK for success, or FAIL if no line found. */ -int search_for_exact_line(buf_T *buf, pos_T *pos, int dir, char_u *pat) +int search_for_exact_line(buf_T *buf, pos_T *pos, Direction dir, char_u *pat) { linenr_T start = 0; char_u *ptr; @@ -1496,10 +1496,11 @@ int search_for_exact_line(buf_T *buf, pos_T *pos, int dir, char_u *pat) * Return FAIL or OK. */ int searchc(cmdarg_T *cap, int t_cmd) + FUNC_ATTR_NONNULL_ALL { - int c = cap->nchar; /* char to search for */ - int dir = cap->arg; /* TRUE for searching forward */ - long count = cap->count1; /* repeat count */ + int c = cap->nchar; // char to search for + Direction dir = cap->arg; // TRUE for searching forward + long count = cap->count1; // repeat count int col; char_u *p; int len; @@ -4462,7 +4463,7 @@ static void search_stat(int dirc, pos_T *pos, void find_pattern_in_path( char_u *ptr, // pointer to search pattern - int dir, // direction of expansion + Direction dir, // direction of expansion size_t len, // length of search pattern bool whole, // match whole words only bool skip_comments, // don't match inside comments diff --git a/src/nvim/spell.c b/src/nvim/spell.c index 797fe41320..5714f5e425 100644 --- a/src/nvim/spell.c +++ b/src/nvim/spell.c @@ -79,7 +79,6 @@ /* for offsetof() */ #include <stddef.h> -#include "nvim/vim.h" #include "nvim/ascii.h" #include "nvim/spell.h" #include "nvim/buffer.h" @@ -6653,7 +6652,7 @@ void spell_dump_compl ( char_u *pat, // leading part of the word int ic, // ignore case - int *dir, // direction for adding matches + Direction *dir, // direction for adding matches int dumpflags_arg // DUMPFLAG_* ) { @@ -6820,7 +6819,9 @@ spell_dump_compl ( // Dumps one word: apply case modifications and append a line to the buffer. // When "lnum" is zero add insert mode completion. -static void dump_word(slang_T *slang, char_u *word, char_u *pat, int *dir, int dumpflags, int wordflags, linenr_T lnum) +static void dump_word(slang_T *slang, char_u *word, char_u *pat, + Direction *dir, int dumpflags, int wordflags, + linenr_T lnum) { bool keepcap = false; char_u *p; @@ -6906,7 +6907,7 @@ dump_prefixes ( slang_T *slang, char_u *word, // case-folded word char_u *pat, - int *dir, + Direction *dir, int dumpflags, int flags, // flags with prefix ID linenr_T startlnum diff --git a/src/nvim/spell.h b/src/nvim/spell.h index ad66df4c5d..e93c82b91d 100644 --- a/src/nvim/spell.h +++ b/src/nvim/spell.h @@ -6,6 +6,7 @@ #include "nvim/spell_defs.h" #include "nvim/ex_cmds_defs.h" #include "nvim/globals.h" +#include "nvim/vim.h" #ifdef INCLUDE_GENERATED_DECLARATIONS # include "spell.h.generated.h" diff --git a/src/nvim/testdir/test_ins_complete.vim b/src/nvim/testdir/test_ins_complete.vim index 1776968afa..6fe1d29434 100644 --- a/src/nvim/testdir/test_ins_complete.vim +++ b/src/nvim/testdir/test_ins_complete.vim @@ -324,7 +324,7 @@ func Test_completefunc_info() set completeopt=menuone set completefunc=CompleteTest call feedkeys("i\<C-X>\<C-U>\<C-R>\<C-R>=string(complete_info())\<CR>\<ESC>", "tx") - call assert_equal("matched{'pum_visible': 1, 'mode': 'function', 'selected': -1, 'items': [{'word': 'matched', 'menu': '', 'user_data': '', 'info': '', 'kind': '', 'abbr': ''}]}", getline(1)) + call assert_equal("matched{'pum_visible': 1, 'mode': 'function', 'selected': 0, 'items': [{'word': 'matched', 'menu': '', 'user_data': '', 'info': '', 'kind': '', 'abbr': ''}]}", getline(1)) bwipe! set completeopt& set completefunc& |