vim-patch:9.1.0956: completion may crash, completion highlight wrong with preview window

Problem:  completion may crash, completion highlight wrong with preview
          window (after v9.1.0954)
Solution: correctly calculate scroll offset, check for preview window
          when adding extra highlighting
          (glepnir)

when there have a preview window prepare_tagpreview
will change curwin to preview window and this may cause
ComplMatchIns check condition not correct. check wp is curwin
and also the type of wp is not a preview or poup info

fixes: https://github.com/vim/vim/issues/16284
closes: https://github.com/vim/vim/pull/16283

8d0bb6dc9f
This commit is contained in:
glepnir
2024-12-24 18:12:50 +08:00
committed by zeertzjq
parent a103ec7449
commit 05eca4c04d
5 changed files with 51 additions and 7 deletions

View File

@@ -1495,7 +1495,7 @@ int win_line(win_T *wp, linenr_T lnum, int startrow, int endrow, int col_rows, s
ptr = line + v; // "line" may have been updated
}
if ((State & MODE_INSERT) && in_curline && ins_compl_active()) {
if ((State & MODE_INSERT) && in_curline && ins_compl_win_active(wp)) {
area_highlighting = true;
}
@@ -1746,7 +1746,7 @@ int win_line(win_T *wp, linenr_T lnum, int startrow, int endrow, int col_rows, s
}
// Check if ComplMatchIns highlight is needed.
if ((State & MODE_INSERT) && in_curline && ins_compl_active()) {
if ((State & MODE_INSERT) && in_curline && ins_compl_win_active(wp)) {
int ins_match_attr = ins_compl_col_range_attr((int)(ptr - line));
if (ins_match_attr > 0) {
search_attr = hl_combine_attr(search_attr, ins_match_attr);

View File

@@ -1722,6 +1722,12 @@ bool ins_compl_active(void)
return compl_started;
}
/// Return true when wp is the actual completion window
bool ins_compl_win_active(win_T *wp)
{
return ins_compl_active() && !(wp->w_p_pvw || wp->w_float_is_info);
}
/// Selected one of the matches. When false the match was edited or using the
/// longest common string.
bool ins_compl_used_match(void)

View File

@@ -906,10 +906,10 @@ static bool pum_set_selected(int n, int repeat)
{
bool resized = false;
int context = pum_height / 2;
int scroll_offset = pum_selected - pum_height;
int prev_selected = pum_selected;
pum_selected = n;
int scroll_offset = pum_selected - pum_height;
unsigned cur_cot_flags = get_cot_flags();
bool use_float = (cur_cot_flags & kOptCotFlagPopup) != 0;
@@ -940,7 +940,7 @@ static bool pum_set_selected(int n, int repeat)
// scroll up; when we did a jump it's probably a PageDown then
// scroll a whole page
if (pum_first < scroll_offset + 3) {
pum_first = MAX(pum_first, scroll_offset + 1);
pum_first = MAX(pum_first + pum_height - 2, scroll_offset + 1);
} else {
pum_first = scroll_offset + 1;
}
@@ -953,7 +953,7 @@ static bool pum_set_selected(int n, int repeat)
if (pum_first > pum_selected - context) {
pum_first = MAX(pum_selected - context, 0); // scroll down
} else if (pum_first < pum_selected + context - pum_height + 1) {
pum_first = pum_selected + context - pum_height + 1; // up
pum_first = pum_selected + context - pum_height + 1; // up
}
}
// adjust for the number of lines displayed