Skip to content

Commit 37f088e

Browse files
committed
patch 9.0.0995: padding before virtual text is highlighted
Problem: Padding before virtual text below is highlighted when 'number' and 'nowrap' are set. Solution: Save and restore n_attr_skip. (closes #11643)
1 parent 267db7c commit 37f088e

File tree

4 files changed

+33
-24
lines changed

4 files changed

+33
-24
lines changed

src/drawline.c

Lines changed: 20 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -141,6 +141,7 @@ typedef struct {
141141
char_u *p_extra_free; // p_extra buffer that needs to be freed
142142
int extra_attr; // attributes for p_extra, should be combined
143143
// with win_attr if needed
144+
int n_attr_skip; // chars to skip before using extra_attr
144145
int c_extra; // extra chars, all the same
145146
int c_final; // final char, mandatory if set
146147
int extra_for_textprop; // wlv.n_extra set for textprop
@@ -149,6 +150,7 @@ typedef struct {
149150
int saved_n_extra;
150151
char_u *saved_p_extra;
151152
int saved_extra_attr;
153+
int saved_n_attr_skip;
152154
int saved_extra_for_textprop;
153155
int saved_c_extra;
154156
int saved_c_final;
@@ -652,13 +654,10 @@ text_prop_position(
652654
int strsize = vim_strsize(*p_extra);
653655
int cells = wrap ? strsize : textprop_size_after_trunc(wp,
654656
tp->tp_flags, before, padding, *p_extra, &n_used);
655-
int cont_on_next_line = below && col_with_padding > win_col_off(wp)
656-
&& !wp->w_p_wrap;
657657

658658
if (wrap || right || above || below || padding > 0 || n_used < *n_extra)
659659
{
660660
int col_off = win_col_off(wp) - win_col_off2(wp);
661-
int skip_add = 0;
662661

663662
if (above)
664663
{
@@ -690,14 +689,10 @@ text_prop_position(
690689
before = 0;
691690
else
692691
n_used = *n_extra;
693-
skip_add = col_off;
694692
}
695693
else
696694
before = 0;
697695
}
698-
else if (below && before > 0)
699-
// include 'number' column et al.
700-
skip_add = col_off;
701696
}
702697

703698
// With 'nowrap' add one to show the "extends" character if needed (it
@@ -707,8 +702,6 @@ text_prop_position(
707702
&& wp->w_lcs_chars.ext != NUL
708703
&& wp->w_p_list)
709704
++n_used;
710-
if (!wp->w_p_wrap && below && padding > 0)
711-
skip_add = col_off;
712705

713706
// add 1 for NUL, 2 for when '…' is used
714707
if (n_attr != NULL)
@@ -763,10 +756,9 @@ text_prop_position(
763756
if (above)
764757
*n_attr -= padding + after;
765758

766-
// Add "skip_add" when starting a new line or wrapping,
767-
// n_attr_skip will then be decremented in the number column.
768-
*n_attr_skip = before + padding
769-
+ (cont_on_next_line || before > 0 ? skip_add : 0);
759+
// n_attr_skip will not be decremented before draw_state is
760+
// WL_LINE
761+
*n_attr_skip = before + padding;
770762
}
771763
}
772764
}
@@ -946,6 +938,7 @@ win_line_start(win_T *wp UNUSED, winlinevars_T *wlv, int save_extra)
946938
wlv->saved_n_extra = wlv->n_extra;
947939
wlv->saved_p_extra = wlv->p_extra;
948940
wlv->saved_extra_attr = wlv->extra_attr;
941+
wlv->saved_n_attr_skip = wlv->n_attr_skip;
949942
wlv->saved_extra_for_textprop = wlv->extra_for_textprop;
950943
wlv->saved_c_extra = wlv->c_extra;
951944
wlv->saved_c_final = wlv->c_final;
@@ -959,7 +952,10 @@ win_line_start(win_T *wp UNUSED, winlinevars_T *wlv, int save_extra)
959952
else
960953
#endif
961954
wlv->saved_char_attr = 0;
955+
956+
// these are not used until restored in win_line_continue()
962957
wlv->n_extra = 0;
958+
wlv->n_attr_skip = 0;
963959
}
964960
}
965961

@@ -978,6 +974,7 @@ win_line_continue(winlinevars_T *wlv)
978974
wlv->c_final = wlv->saved_c_final;
979975
wlv->p_extra = wlv->saved_p_extra;
980976
wlv->extra_attr = wlv->saved_extra_attr;
977+
wlv->n_attr_skip = wlv->saved_n_attr_skip;
981978
wlv->extra_for_textprop = wlv->saved_extra_for_textprop;
982979
wlv->char_attr = wlv->saved_char_attr;
983980
}
@@ -1021,7 +1018,6 @@ win_line(
10211018
// prec until it's been used
10221019

10231020
int n_attr = 0; // chars with special attr
1024-
int n_attr_skip = 0; // chars to skip bef. using wlv.extra_attr
10251021
int saved_attr2 = 0; // char_attr saved for n_attr
10261022
int n_attr3 = 0; // chars with overruling special attr
10271023
int saved_attr3 = 0; // char_attr saved for n_attr3
@@ -2063,7 +2059,7 @@ win_line(
20632059
wlv.vcol,
20642060
wlv.col,
20652061
&wlv.n_extra, &wlv.p_extra,
2066-
&n_attr, &n_attr_skip);
2062+
&n_attr, &wlv.n_attr_skip);
20672063
if (wlv.p_extra != prev_p_extra)
20682064
{
20692065
// wlv.p_extra was allocated
@@ -2105,9 +2101,9 @@ win_line(
21052101
{
21062102
wlv.n_extra -= skip_cells;
21072103
wlv.p_extra += skip_cells;
2108-
n_attr_skip -= skip_cells;
2109-
if (n_attr_skip < 0)
2110-
n_attr_skip = 0;
2104+
wlv.n_attr_skip -= skip_cells;
2105+
if (wlv.n_attr_skip < 0)
2106+
wlv.n_attr_skip = 0;
21112107
skip_cells = 0;
21122108
}
21132109
else
@@ -2116,7 +2112,7 @@ win_line(
21162112
// it and advance to the next one
21172113
skip_cells -= wlv.n_extra;
21182114
wlv.n_extra = 0;
2119-
n_attr_skip = 0;
2115+
wlv.n_attr_skip = 0;
21202116
bail_out = TRUE;
21212117
}
21222118
}
@@ -3337,8 +3333,8 @@ win_line(
33373333

33383334
// Use "wlv.extra_attr", but don't override visual selection
33393335
// highlighting, unless text property overrides.
3340-
// Don't use "wlv.extra_attr" until n_attr_skip is zero.
3341-
if (n_attr_skip == 0 && n_attr > 0
3336+
// Don't use "wlv.extra_attr" until wlv.n_attr_skip is zero.
3337+
if (wlv.n_attr_skip == 0 && n_attr > 0
33423338
&& wlv.draw_state == WL_LINE
33433339
&& (!attr_pri
33443340
#ifdef FEAT_PROP_POPUP
@@ -3828,10 +3824,10 @@ win_line(
38283824

38293825
// restore attributes after last 'listchars' or 'number' char
38303826
if (n_attr > 0 && wlv.draw_state == WL_LINE
3831-
&& n_attr_skip == 0 && --n_attr == 0)
3827+
&& wlv.n_attr_skip == 0 && --n_attr == 0)
38323828
wlv.char_attr = saved_attr2;
3833-
if (n_attr_skip > 0)
3834-
--n_attr_skip;
3829+
if (wlv.n_attr_skip > 0)
3830+
--wlv.n_attr_skip;
38353831

38363832
// At end of screen line and there is more to come: Display the line
38373833
// so far. If there is no more to display it is caught above.
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
| +0#af5f00255#ffffff0@1|1| >v+0#0000000&|i|m|9|s|c|r|i|p|t| @45
2+
| +0#af5f00255&@1|2| | +0#0000000&@55
3+
| +0#af5f00255&@3| +0#0000000&|T+0#ffffff16#e000002|h|e| |q|u|i|c|k| |b|r|o|w|n| |f|o|x| |j|u|m|p|s| |o|v|e|r| |t|h|e| |l|a|z|y| |d|o|g| +0#0000000#ffffff0@11
4+
| +0#af5f00255&@1|3| |t+0#0000000&|h|r|e@1| @50
5+
| +0#af5f00255&@1|4| | +0#0000000&@55
6+
| +0#af5f00255&@3|T+0#0000000#ffd7ff255|h|e| |s|l|o|w| |f|o|x| |b|u|m|p|s| |i|n|t|o| |t|h|e| |l|a|z|y| |d|o|g| +0&#ffffff0@19
7+
|~+0#4040ff13&| @58
8+
|:+0#0000000&|s|e|t| |n|o|w|r|a|p| @30|1|,|1| @10|A|l@1|

src/testdir/test_textprop.vim

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2747,6 +2747,9 @@ func Test_prop_with_text_below_after_empty()
27472747
call term_sendkeys(buf, ":set number\<CR>")
27482748
call VerifyScreenDump(buf, 'Test_prop_below_after_empty_2', {})
27492749

2750+
call term_sendkeys(buf, ":set nowrap\<CR>")
2751+
call VerifyScreenDump(buf, 'Test_prop_below_after_empty_3', {})
2752+
27502753
call StopVimInTerminal(buf)
27512754
endfunc
27522755

src/version.c

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

696696
static int included_patches[] =
697697
{ /* Add new patch number below this line */
698+
/**/
699+
995,
698700
/**/
699701
994,
700702
/**/

0 commit comments

Comments
 (0)