Patch 8.2.1907
Problem: Complete_info().selected may be wrong.
Solution: Update cp_number if it was never set. (issue #6945)
Files: src/insexpand.c, src/testdir/test_ins_complete.vim
*** ../vim-8.2.1906/src/insexpand.c 2020-09-12 22:52:53.582315764 +0200
--- src/insexpand.c 2020-10-26 19:18:42.470503841 +0100
***************
*** 2498,2503 ****
--- 2498,2553 ----
return (char_u *)"";
}
+ static void
+ ins_compl_update_sequence_numbers()
+ {
+ 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;
+ }
+ }
+
/*
* Get complete information
*/
***************
*** 2584,2591 ****
}
if (ret == OK && (what_flag & CI_WHAT_SELECTED))
! ret = dict_add_number(retdict, "selected", (compl_curr_match != NULL) ?
! compl_curr_match->cp_number - 1 : -1);
// TODO
// if (ret == OK && (what_flag & CI_WHAT_INSERTED))
--- 2634,2645 ----
}
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 = dict_add_number(retdict, "selected", compl_curr_match != NULL
! ? compl_curr_match->cp_number - 1 : -1);
! }
// TODO
// if (ret == OK && (what_flag & CI_WHAT_INSERTED))
***************
*** 4009,4067 ****
{
edit_submode_extra = (char_u *)_("The only match");
edit_submode_highl = HLF_COUNT;
! compl_curr_match->cp_number = 0;
}
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;
! }
! }
// The match should always have a sequence number now, this is
// just a safety check.
--- 4063,4075 ----
{
edit_submode_extra = (char_u *)_("The only match");
edit_submode_highl = HLF_COUNT;
! compl_curr_match->cp_number = 1;
}
else
{
// Update completion sequence number when needed.
if (compl_curr_match->cp_number == -1)
! ins_compl_update_sequence_numbers();
// The match should always have a sequence number now, this is
// just a safety check.
*** ../vim-8.2.1906/src/testdir/test_ins_complete.vim 2020-10-25
13:22:38.216253317 +0100
--- src/testdir/test_ins_complete.vim 2020-10-26 19:20:40.934106723 +0100
***************
*** 325,331 ****
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))
bwipe!
set completeopt&
set completefunc&
--- 325,331 ----
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': 0, 'items': [{'word': 'matched', 'menu': '', 'user_data': '',
'info': '', 'kind': '', 'abbr': ''}]}", getline(1))
bwipe!
set completeopt&
set completefunc&
*** ../vim-8.2.1906/src/version.c 2020-10-26 18:46:49.480589241 +0100
--- src/version.c 2020-10-26 19:21:13.489999378 +0100
***************
*** 752,753 ****
--- 752,755 ----
{ /* Add new patch number below this line */
+ /**/
+ 1907,
/**/
--
Don't drink and drive. You might hit a bump and spill your beer.
/// Bram Moolenaar -- [email protected] -- http://www.Moolenaar.net \\\
/// sponsor Vim, vote for features -- http://www.Vim.org/sponsor/ \\\
\\\ an exciting new programming language -- http://www.Zimbu.org ///
\\\ help me help AIDS victims -- http://ICCF-Holland.org ///
--
--
You received this message from the "vim_dev" maillist.
Do not top-post! Type your reply below the text you are replying to.
For more information, visit http://www.vim.org/maillist.php
---
You received this message because you are subscribed to the Google Groups
"vim_dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To view this discussion on the web visit
https://groups.google.com/d/msgid/vim_dev/202010261823.09QINIap1657046%40masaka.moolenaar.net.