patch 9.1.0945: ComplMatchIns highlight doesn't end after inserted text

Problem:  ComplMatchIns highlight doesn't end after inserted text.
Solution: Handle ComplMatchIns highlight more like search highlight.
          Fix off-by-one error. Handle deleting text properly.
          (zeertzjq)

closes: #16244

Signed-off-by: zeertzjq <zeertzjq@outlook.com>
Signed-off-by: Christian Brabandt <cb@256bit.org>
This commit is contained in:
zeertzjq
2024-12-18 21:12:25 +01:00
committed by Christian Brabandt
parent beccb33977
commit f25d8f9312
16 changed files with 283 additions and 19 deletions

View File

@ -1172,7 +1172,8 @@ win_line(
int vi_attr = 0; // attributes for Visual and incsearch
// highlighting
int area_attr = 0; // attributes desired by highlighting
int search_attr = 0; // attributes desired by 'hlsearch'
int search_attr = 0; // attributes desired by 'hlsearch' or
// ComplMatchIns
#ifdef FEAT_SYN_HL
int vcol_save_attr = 0; // saved attr for 'cursorcolumn'
int syntax_attr = 0; // attributes desired by syntax
@ -1213,7 +1214,7 @@ win_line(
int word_end = 0; // last byte with same spell_attr
int cur_checked_col = 0; // checked column for current line
#endif
int extra_check = 0; // has extra highlighting
int extra_check = FALSE; // has extra highlighting
int multi_attr = 0; // attributes desired by multibyte
int mb_l = 1; // multi-byte byte length
int mb_c = 0; // decoded multi-byte character
@ -1868,6 +1869,9 @@ win_line(
}
#endif
if ((State & MODE_INSERT) && in_curline && ins_compl_active())
area_highlighting = TRUE;
#ifdef FEAT_SYN_HL
// Cursor line highlighting for 'cursorline' in the current window.
if (wp->w_p_cul && lnum == wp->w_cursor.lnum)
@ -2389,9 +2393,9 @@ win_line(
|| (noinvcur && (colnr_T)wlv.vcol == wp->w_virtcol)))
*area_attr_p = 0; // stop highlighting
#ifdef FEAT_SEARCH_EXTRA
if (wlv.n_extra == 0)
{
#ifdef FEAT_SEARCH_EXTRA
// Check for start/end of 'hlsearch' and other matches.
// After end, check for start/end of next match.
// When another match, have to check for start again.
@ -2406,9 +2410,21 @@ win_line(
// and bad things happen.
if (*ptr == NUL)
has_match_conc = 0;
}
#else
search_attr = 0;
#endif
// Check if ComplMatchIns highlight is needed.
if ((State & MODE_INSERT) && in_curline && ins_compl_active())
{
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);
}
}
#ifdef FEAT_DIFF
if (wlv.diff_hlf != (hlf_T)0)
{
@ -2562,15 +2578,6 @@ win_line(
#endif
}
// Apply ComplMatchIns highlight if needed.
if (wlv.draw_state == WL_LINE
&& (State & MODE_INSERT) && in_curline && ins_compl_active())
{
int ins_match_attr = ins_compl_col_range_attr((int)(ptr - line));
if (ins_match_attr > 0)
wlv.char_attr = hl_combine_attr(wlv.char_attr, ins_match_attr);
}
// combine attribute with 'wincolor'
if (wlv.win_attr != 0)
{

View File

@ -262,7 +262,7 @@ static char *(highlight_init_both[]) = {
"default link PmenuMatchSel PmenuSel",
"default link PmenuExtra Pmenu",
"default link PmenuExtraSel PmenuSel",
"default link ComplMatchIns Normal",
CENT("ComplMatchIns cterm=NONE", "ComplMatchIns gui=NONE"),
CENT("Normal cterm=NONE", "Normal gui=NONE"),
NULL
};

View File

@ -912,7 +912,7 @@ ins_compl_insert_bytes(char_u *p, int len)
if (len == -1)
len = (int)STRLEN(p);
ins_bytes_len(p, len);
compl_ins_end_col = curwin->w_cursor.col - 1;
compl_ins_end_col = curwin->w_cursor.col;
}
/*
@ -2437,7 +2437,7 @@ ins_compl_stop(int c, int prev_mode, int retval)
int compl_len = get_compl_len();
if ((int)plen > compl_len)
ins_compl_insert_bytes(p + compl_len, (int)(plen - compl_len));
ins_compl_insert_bytes(p + compl_len, (int)plen - compl_len);
}
retval = TRUE;
}
@ -4264,6 +4264,7 @@ ins_compl_delete(void)
if (stop_arrow() == FAIL)
return;
backspace_until_column(col);
compl_ins_end_col = curwin->w_cursor.col;
}
// TODO: is this sufficient for redrawing? Redrawing everything causes

View File

@ -0,0 +1,20 @@
|α+0&#ffffff0|β|γ| |f+0#ff404010&|o@1> +0#0000000&|f|o@1| @63
|~+0#4040ff13&| @1| +0#0000001#e0e0e08|f|o@1| @11| +0#4040ff13#ffffff0@55
|~| @1| +0#0000001#ffd7ff255|b|a|r| @11| +0#4040ff13#ffffff0@55
|~| @1| +0#0000001#ffd7ff255|你*&|好| +&@10| +0#4040ff13#ffffff0@55
|~| @73
|~| @73
|~| @73
|~| @73
|~| @73
|~| @73
|~| @73
|~| @73
|~| @73
|~| @73
|~| @73
|~| @73
|~| @73
|~| @73
|~| @73
|-+2#0000000&@1| |O|m|n|i| |c|o|m|p|l|e|t|i|o|n| |(|^|O|^|N|^|P|)| |m+0#00e0003&|a|t|c|h| |1| |o|f| |3| +0#0000000&@34

View File

@ -0,0 +1,20 @@
|α+0&#ffffff0|β|γ| > |f|o@1| @66
|~+0#4040ff13&| @1| +0#0000001#ffd7ff255|f|o@1| @11| +0#4040ff13#ffffff0@55
|~| @1| +0#0000001#ffd7ff255|b|a|r| @11| +0#4040ff13#ffffff0@55
|~| @1| +0#0000001#ffd7ff255|你*&|好| +&@10| +0#4040ff13#ffffff0@55
|~| @73
|~| @73
|~| @73
|~| @73
|~| @73
|~| @73
|~| @73
|~| @73
|~| @73
|~| @73
|~| @73
|~| @73
|~| @73
|~| @73
|~| @73
|-+2#0000000&@1| |O|m|n|i| |c|o|m|p|l|e|t|i|o|n| |(|^|O|^|N|^|P|)| |B+0#e000002&|a|c|k| |a|t| |o|r|i|g|i|n|a|l| +0#0000000&@30

View File

@ -0,0 +1,20 @@
|α+0&#ffffff0|β|γ| |你*0#ff404010&|好> +0#0000000&|f|o@1| @62
|~+0#4040ff13&| @1| +0#0000001#ffd7ff255|f|o@1| @11| +0#4040ff13#ffffff0@55
|~| @1| +0#0000001#ffd7ff255|b|a|r| @11| +0#4040ff13#ffffff0@55
|~| @1| +0#0000001#e0e0e08|你*&|好| +&@10| +0#4040ff13#ffffff0@55
|~| @73
|~| @73
|~| @73
|~| @73
|~| @73
|~| @73
|~| @73
|~| @73
|~| @73
|~| @73
|~| @73
|~| @73
|~| @73
|~| @73
|~| @73
|-+2#0000000&@1| |O|m|n|i| |c|o|m|p|l|e|t|i|o|n| |(|^|O|^|N|^|P|)| |m+0#00e0003&|a|t|c|h| |3| |o|f| |3| +0#0000000&@34

View File

@ -0,0 +1,20 @@
|α+0&#ffffff0|β|γ| |你*&|好> +&|f|o@1| @62
|~+0#4040ff13&| @73
|~| @73
|~| @73
|~| @73
|~| @73
|~| @73
|~| @73
|~| @73
|~| @73
|~| @73
|~| @73
|~| @73
|~| @73
|~| @73
|~| @73
|~| @73
|~| @73
|~| @73
|-+2#0000000&@1| |I|N|S|E|R|T| |-@1| +0&&@44|1|,|1|4|-|9| @7|A|l@1|

View File

@ -0,0 +1,20 @@
|a+8&#40ff4011@2| |f|o@1> |b@2| @63
|~+0#4040ff13#4040ff13| @1| +0#0000001#e0e0e08|f|o@1| @11| +0#4040ff13#4040ff13@55
|~| @1| +0#0000001#ffd7ff255|b|a|r| @11| +0#4040ff13#4040ff13@55
|~| @1| +0#0000001#ffd7ff255|你*&|好| +&@10| +0#4040ff13#4040ff13@55
|~| @73
|~| @73
|~| @73
|~| @73
|~| @73
|~| @73
|~| @73
|~| @73
|~| @73
|~| @73
|~| @73
|~| @73
|~| @73
|~| @73
|~| @73
|-+2#0000000&@1| |O|m|n|i| |c|o|m|p|l|e|t|i|o|n| |(|^|O|^|N|^|P|)| |m+0#00e0003&|a|t|c|h| |1| |o|f| |3| +0#0000000&@34

View File

@ -0,0 +1,20 @@
|a+8&#40ff4011@2| > |b@2| @66
|~+0#4040ff13#4040ff13| @73
|~| @73
|~| @73
|~| @73
|~| @73
|~| @73
|~| @73
|~| @73
|~| @73
|~| @73
|~| @73
|~| @73
|~| @73
|~| @73
|~| @73
|~| @73
|~| @73
|~| @73
|-+2#0000000&@1| |I|N|S|E|R|T| |-@1| +0&&@44|1|,|5| @10|A|l@1|

View File

@ -0,0 +1,20 @@
|a+8&#40ff4011@2| |f+8#ffff4012#ff404010|o@1> +8#0000000#40ff4011|b@2| @63
|~+0#4040ff13#4040ff13| @1| +0#0000001#e0e0e08|f|o@1| @11| +0#4040ff13#4040ff13@55
|~| @1| +0#0000001#ffd7ff255|b|a|r| @11| +0#4040ff13#4040ff13@55
|~| @1| +0#0000001#ffd7ff255|你*&|好| +&@10| +0#4040ff13#4040ff13@55
|~| @73
|~| @73
|~| @73
|~| @73
|~| @73
|~| @73
|~| @73
|~| @73
|~| @73
|~| @73
|~| @73
|~| @73
|~| @73
|~| @73
|~| @73
|-+2#0000000&@1| |O|m|n|i| |c|o|m|p|l|e|t|i|o|n| |(|^|O|^|N|^|P|)| |m+0#00e0003&|a|t|c|h| |1| |o|f| |3| +0#0000000&@34

View File

@ -0,0 +1,20 @@
|a+8&#40ff4011@2| > |b@2| @66
|~+0#4040ff13#4040ff13| @1| +0#0000001#ffd7ff255|f|o@1| @11| +0#4040ff13#4040ff13@55
|~| @1| +0#0000001#ffd7ff255|b|a|r| @11| +0#4040ff13#4040ff13@55
|~| @1| +0#0000001#ffd7ff255|你*&|好| +&@10| +0#4040ff13#4040ff13@55
|~| @73
|~| @73
|~| @73
|~| @73
|~| @73
|~| @73
|~| @73
|~| @73
|~| @73
|~| @73
|~| @73
|~| @73
|~| @73
|~| @73
|~| @73
|-+2#0000000&@1| |O|m|n|i| |c|o|m|p|l|e|t|i|o|n| |(|^|O|^|N|^|P|)| |B+0#e000002&|a|c|k| |a|t| |o|r|i|g|i|n|a|l| +0#0000000&@30

View File

@ -0,0 +1,20 @@
|a+8&#40ff4011@2| |你*8#ffff4012#ff404010|好> +8#0000000#40ff4011|b@2| @62
|~+0#4040ff13#4040ff13| @1| +0#0000001#ffd7ff255|f|o@1| @11| +0#4040ff13#4040ff13@55
|~| @1| +0#0000001#ffd7ff255|b|a|r| @11| +0#4040ff13#4040ff13@55
|~| @1| +0#0000001#e0e0e08|你*&|好| +&@10| +0#4040ff13#4040ff13@55
|~| @73
|~| @73
|~| @73
|~| @73
|~| @73
|~| @73
|~| @73
|~| @73
|~| @73
|~| @73
|~| @73
|~| @73
|~| @73
|~| @73
|~| @73
|-+2#0000000&@1| |O|m|n|i| |c|o|m|p|l|e|t|i|o|n| |(|^|O|^|N|^|P|)| |m+0#00e0003&|a|t|c|h| |3| |o|f| |3| +0#0000000&@34

View File

@ -0,0 +1,20 @@
|a+8&#40ff4011@2| > |b@2| @66
|~+0#4040ff13#4040ff13| @73
|~| @73
|~| @73
|~| @73
|~| @73
|~| @73
|~| @73
|~| @73
|~| @73
|~| @73
|~| @73
|~| @73
|~| @73
|~| @73
|~| @73
|~| @73
|~| @73
|~| @73
|-+2#0000000&@1| |I|N|S|E|R|T| |-@1| +0&&@44|1|,|5| @10|A|l@1|

View File

@ -305,7 +305,7 @@ endfunc
" Test that mouse shape is restored to Normal mode after using "gq" when
" 'indentexpr' executes :normal.
func Test_indent_norm_with_gq()
func Test_mouse_shape_indent_norm_with_gq()
CheckFeature mouseshape
CheckCanRunGui

View File

@ -1746,13 +1746,67 @@ func Test_pum_matchins_highlight()
call TermWait(buf)
call term_sendkeys(buf, "Sαβγ \<C-X>\<C-O>\<C-Y>")
call VerifyScreenDump(buf, 'Test_pum_matchins_04', {})
call term_sendkeys(buf, "\<C-E>\<Esc>")
call term_sendkeys(buf, "\<Esc>")
" restore after cancel completion
call TermWait(buf)
call term_sendkeys(buf, "Sαβγ \<C-X>\<C-O>\<Space>")
call VerifyScreenDump(buf, 'Test_pum_matchins_05', {})
call term_sendkeys(buf, "\<C-E>\<Esc>")
call term_sendkeys(buf, "\<Esc>")
" text after the inserted text shouldn't be highlighted
call TermWait(buf)
call term_sendkeys(buf, "0ea \<C-X>\<C-O>")
call VerifyScreenDump(buf, 'Test_pum_matchins_07', {})
call term_sendkeys(buf, "\<C-P>")
call VerifyScreenDump(buf, 'Test_pum_matchins_08', {})
call term_sendkeys(buf, "\<C-P>")
call VerifyScreenDump(buf, 'Test_pum_matchins_09', {})
call term_sendkeys(buf, "\<C-Y>")
call VerifyScreenDump(buf, 'Test_pum_matchins_10', {})
call term_sendkeys(buf, "\<Esc>")
call StopVimInTerminal(buf)
endfunc
func Test_pum_matchins_highlight_combine()
CheckScreendump
let lines =<< trim END
func Omni_test(findstart, base)
if a:findstart
return col(".")
endif
return [#{word: "foo"}, #{word: "bar"}, #{word: "你好"}]
endfunc
set omnifunc=Omni_test
hi Normal ctermbg=blue
hi CursorLine cterm=underline ctermbg=green
set cursorline
call setline(1, 'aaa bbb')
END
call writefile(lines, 'Xscript', 'D')
let buf = RunVimInTerminal('-S Xscript', {})
" when ComplMatchIns is not set, CursorLine applies normally
call term_sendkeys(buf, "0ea \<C-X>\<C-O>")
call VerifyScreenDump(buf, 'Test_pum_matchins_combine_01', {})
call term_sendkeys(buf, "\<C-E>")
call VerifyScreenDump(buf, 'Test_pum_matchins_combine_02', {})
call term_sendkeys(buf, "\<BS>\<Esc>")
" when ComplMatchIns is set, it is applied over CursorLine
call TermWait(buf)
call term_sendkeys(buf, ":hi ComplMatchIns ctermbg=red ctermfg=yellow\<CR>")
call TermWait(buf)
call term_sendkeys(buf, "0ea \<C-X>\<C-O>")
call VerifyScreenDump(buf, 'Test_pum_matchins_combine_03', {})
call term_sendkeys(buf, "\<C-P>")
call VerifyScreenDump(buf, 'Test_pum_matchins_combine_04', {})
call term_sendkeys(buf, "\<C-P>")
call VerifyScreenDump(buf, 'Test_pum_matchins_combine_05', {})
call term_sendkeys(buf, "\<C-E>")
call VerifyScreenDump(buf, 'Test_pum_matchins_combine_06', {})
call term_sendkeys(buf, "\<Esc>")
call StopVimInTerminal(buf)
endfunc

View File

@ -704,6 +704,8 @@ static char *(features[]) =
static int included_patches[] =
{ /* Add new patch number below this line */
/**/
945,
/**/
944,
/**/