Skip to content

Commit

Permalink
patch 9.1.1059: completion: input text deleted with preinsert when ad…
Browse files Browse the repository at this point in the history
…ding leader

Problem:  completion: input text deleted with preinsert when adding leader
Solution: remove compl_length and check the ptr for being equal
          to pattern when preinsert is active (glepnir)

closes: #16545

Signed-off-by: glepnir <[email protected]>
Signed-off-by: Christian Brabandt <[email protected]>
  • Loading branch information
glepnir authored and chrisbra committed Jan 31, 2025
1 parent fe0a9a3 commit bfb4eea
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 2 deletions.
4 changes: 2 additions & 2 deletions src/insexpand.c
Original file line number Diff line number Diff line change
Expand Up @@ -4094,7 +4094,7 @@ get_next_default_completion(ins_compl_next_state_T *st, pos_T *start_pos)
if (!in_fuzzy)
ptr = ins_compl_get_next_word_or_line(st->ins_buf, st->cur_match_pos,
&len, &cont_s_ipos);
if (ptr == NULL)
if (ptr == NULL || (ins_compl_has_preinsert() && STRCMP(ptr, compl_pattern.string) == 0))
continue;

if (ins_compl_add_infercase(ptr, len, p_ic,
Expand Down Expand Up @@ -4342,7 +4342,7 @@ ins_compl_delete(void)
int has_preinsert = ins_compl_preinsert_effect();
if (has_preinsert)
{
col = compl_col + ins_compl_leader_len() - compl_length;
col += ins_compl_leader_len();
curwin->w_cursor.col = compl_ins_end_col;
}

Expand Down
4 changes: 4 additions & 0 deletions src/testdir/test_ins_complete.vim
Original file line number Diff line number Diff line change
Expand Up @@ -3112,6 +3112,10 @@ function Test_completeopt_preinsert()
call assert_equal("hello hero", getline('.'))
call assert_equal(2, col('.'))

call feedkeys("Shello hero\<CR>h\<C-X>\<C-N>er", 'tx')
call assert_equal("hero", getline('.'))
call assert_equal(3, col('.'))

" can not work with fuzzy
set cot+=fuzzy
call feedkeys("S\<C-X>\<C-O>", 'tx')
Expand Down
2 changes: 2 additions & 0 deletions src/version.c
Original file line number Diff line number Diff line change
Expand Up @@ -704,6 +704,8 @@ static char *(features[]) =

static int included_patches[] =
{ /* Add new patch number below this line */
/**/
1059,
/**/
1058,
/**/
Expand Down

0 comments on commit bfb4eea

Please sign in to comment.