Skip to content

Commit 6eda17d

Browse files
committed
patch 9.0.0452: Visual highlighting extends into virtual text prop
Problem: Visual highlighting extends into virtual text prop. Solution: Do not highlight what isn't actually selected. Fix ordering of stored text props.
1 parent c9dc03f commit 6eda17d

6 files changed

Lines changed: 52 additions & 5 deletions

File tree

src/drawline.c

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -670,6 +670,7 @@ win_line(
670670
int text_prop_follows = FALSE; // another text prop to display
671671
int saved_search_attr = 0; // search_attr to be used when n_extra
672672
// goes to zero
673+
int saved_area_attr = 0; // idem for area_attr
673674
#endif
674675
#ifdef FEAT_SPELL
675676
int has_spell = FALSE; // this buffer has spell checking
@@ -1846,8 +1847,12 @@ win_line(
18461847
extra_for_textprop = TRUE;
18471848
extra_attr = used_attr;
18481849
n_attr = mb_charlen(p);
1850+
// restore search_attr and area_attr when n_extra
1851+
// is down to zero
18491852
saved_search_attr = search_attr;
1850-
search_attr = 0; // restore when n_extra is zero
1853+
saved_area_attr = area_attr;
1854+
search_attr = 0;
1855+
area_attr = 0;
18511856
text_prop_attr = 0;
18521857
text_prop_attr_comb = 0;
18531858
if (*ptr == NUL)
@@ -2203,6 +2208,8 @@ win_line(
22032208
in_linebreak = FALSE;
22042209
if (search_attr == 0)
22052210
search_attr = saved_search_attr;
2211+
if (area_attr == 0 && *ptr != NUL)
2212+
area_attr = saved_area_attr;
22062213
}
22072214
#endif
22082215
}
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
| +0#0000e05#a8a8a8255@1| +0#af5f00255#ffffff0@1|1| |f+0#0000000#ffff4012|i|r|s|t| |t|h|i|n|g| |a|b|o|v|e| @36
2+
| +0#0000e05#a8a8a8255@1| +0#af5f00255#ffffff0@3|s+0#0000000#ffd7ff255|e|c|o|n|d| |t|h|i|n|g| |a|b|o|v|e| @35
3+
| +0#0000e05#a8a8a8255@1| +0#af5f00255#ffffff0@3|i+0#0000000#e0e0e08|n|s|e|r|t|e>d+0&#ffffff0| |o|n|e| |t|w|o| @37
4+
| +0#0000e05#a8a8a8255@1| +0#af5f00255#ffffff0@3|b+0#0000000#5fd7ff255|e|l|o|w| +0&#ffffff0@48
5+
| +0#0000e05#a8a8a8255@1| +0#af5f00255#ffffff0@1|2| |t+0#0000000&|h|r|e@1| |f|o|u|r| @43
6+
| +0#0000e05#a8a8a8255@1| +0#af5f00255#ffffff0@1|3| | +0#0000000&@2|a+0&#ffff4012|n|o|t|h|e|r| |t|h|i|n|g| @37
7+
| +0#0000e05#a8a8a8255@1| +0#af5f00255#ffffff0@3|f+0#0000000&|i|v|e| |s|i|x| @45
8+
|~+0#4040ff13&| @58
9+
|-+2#0000000&@1| |V|I|S|U|A|L| |-@1| +0&&@19|8| @8|1|,|8|-|1@1|6| @6|A|l@1|
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
| +0#0000e05#a8a8a8255@1| +0#af5f00255#ffffff0@1|1| |f+0#0000000#ffff4012|i|r|s|t| |t|h|i|n|g| |a|b|o|v|e| @36
2+
| +0#0000e05#a8a8a8255@1| +0#af5f00255#ffffff0@3|s+0#0000000#ffd7ff255|e|c|o|n|d| |t|h|i|n|g| |a|b|o|v|e| @35
3+
| +0#0000e05#a8a8a8255@1| +0#af5f00255#ffffff0@3|i+0#0000000#e0e0e08|n|s|e|r|t|e>d+0&#ffffff0| +0&#e0e0e08|o|n|e| |t|w|o| +0&#ffffff0@37
4+
| +0#0000e05#a8a8a8255@1| +0#af5f00255#ffffff0@3|b+0#0000000#5fd7ff255|e|l|o|w| +0#4040ff13#ffffff0| +0#0000000&@47
5+
| +0#0000e05#a8a8a8255@1| +0#af5f00255#ffffff0@1|2| |t+0#0000000&|h|r|e@1| |f|o|u|r| @43
6+
| +0#0000e05#a8a8a8255@1| +0#af5f00255#ffffff0@1|3| | +0#0000000&@2|a+0&#ffff4012|n|o|t|h|e|r| |t|h|i|n|g| @37
7+
| +0#0000e05#a8a8a8255@1| +0#af5f00255#ffffff0@3|f+0#0000000&|i|v|e| |s|i|x| @45
8+
|~+0#4040ff13&| @58
9+
|-+2#0000000&@1| |V|I|S|U|A|L| |L|I|N|E| |-@1| +0&&@14|1| @8|1|,|8|-|1@1|6| @6|A|l@1|

src/testdir/test_textprop.vim

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2855,11 +2855,15 @@ func Test_props_with_text_above()
28552855
call setline(1, ['one two', 'three four', 'five six'])
28562856
call prop_type_add('above1', #{highlight: 'Search'})
28572857
call prop_type_add('above2', #{highlight: 'DiffChange'})
2858+
call prop_type_add('below', #{highlight: 'DiffAdd'})
28582859
call prop_add(1, 0, #{type: 'above1', text: 'first thing above', text_align: 'above'})
28592860
call prop_add(1, 0, #{type: 'above2', text: 'second thing above', text_align: 'above'})
28602861
call prop_add(3, 0, #{type: 'above1', text: 'another thing', text_align: 'above', text_padding_left: 3})
28612862

28622863
normal gglllj
2864+
func AddPropBelow()
2865+
call prop_add(1, 0, #{type: 'below', text: 'below', text_align: 'below'})
2866+
endfunc
28632867
END
28642868
call writefile(lines, 'XscriptPropsWithTextAbove', 'D')
28652869
let buf = RunVimInTerminal('-S XscriptPropsWithTextAbove', #{rows: 9, cols: 60})
@@ -2876,6 +2880,12 @@ func Test_props_with_text_above()
28762880
call term_sendkeys(buf, ":set nowrap\<CR>gg$j")
28772881
call VerifyScreenDump(buf, 'Test_prop_with_text_above_5', {})
28782882

2883+
call term_sendkeys(buf, ":call AddPropBelow()\<CR>")
2884+
call term_sendkeys(buf, "ggve")
2885+
call VerifyScreenDump(buf, 'Test_prop_with_text_above_6', {})
2886+
call term_sendkeys(buf, "V")
2887+
call VerifyScreenDump(buf, 'Test_prop_with_text_above_7', {})
2888+
28792889
call StopVimInTerminal(buf)
28802890
endfunc
28812891

src/textprop.c

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -232,8 +232,9 @@ prop_add_one(
232232

233233
for (lnum = start_lnum; lnum <= end_lnum; ++lnum)
234234
{
235-
colnr_T col; // start column
236-
long length; // in bytes
235+
colnr_T col; // start column use in tp_col
236+
colnr_T sort_col; // column where it appears
237+
long length; // in bytes
237238

238239
// Fetch the line to get the ml_line_len field updated.
239240
proplen = get_text_props(buf, lnum, &props, TRUE);
@@ -248,6 +249,7 @@ prop_add_one(
248249
semsg(_(e_invalid_column_number_nr), (long)start_col);
249250
goto theend;
250251
}
252+
sort_col = col;
251253

252254
if (lnum == end_lnum)
253255
length = end_col - col;
@@ -263,7 +265,9 @@ prop_add_one(
263265
length = 1; // text is placed on one character
264266
if (col == 0)
265267
{
266-
col = MAXCOL; // after the line
268+
col = MAXCOL; // before or after the line
269+
if ((text_flags & TP_FLAG_ALIGN_ABOVE) == 0)
270+
sort_col = MAXCOL;
267271
length += text_padding_left;
268272
}
269273
}
@@ -280,9 +284,15 @@ prop_add_one(
280284
// the text, we need to copy them as bytes before using it as a struct.
281285
for (i = 0; i < proplen; ++i)
282286
{
287+
colnr_T prop_col;
288+
283289
mch_memmove(&tmp_prop, props + i * sizeof(textprop_T),
284290
sizeof(textprop_T));
285-
if (tmp_prop.tp_col >= col)
291+
// col is MAXCOL when the text goes above or after the line, when
292+
// above we should use column zero for sorting
293+
prop_col = (tmp_prop.tp_flags & TP_FLAG_ALIGN_ABOVE)
294+
? 0 : tmp_prop.tp_col;
295+
if (prop_col >= sort_col)
286296
break;
287297
}
288298
newprops = newtext + textlen;

src/version.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -703,6 +703,8 @@ static char *(features[]) =
703703

704704
static int included_patches[] =
705705
{ /* Add new patch number below this line */
706+
/**/
707+
452,
706708
/**/
707709
451,
708710
/**/

0 commit comments

Comments
 (0)