Skip to content

Commit

Permalink
patch 9.0.0716: with 'nowrap' virtual text "after" does not scroll left
Browse files Browse the repository at this point in the history
Problem:    With 'nowrap' virtual text "after" does not scroll left.
Solution:   Skip part of the virtual text that is left of the window.
            (closes vim#11320)  Fix going beyond the last column of the window.
  • Loading branch information
brammool committed Oct 10, 2022
1 parent 801cd35 commit cd10541
Show file tree
Hide file tree
Showing 7 changed files with 100 additions and 17 deletions.
53 changes: 48 additions & 5 deletions src/drawline.c
Original file line number Diff line number Diff line change
Expand Up @@ -975,7 +975,11 @@ win_line(
int n_attr3 = 0; // chars with overruling special attr
int saved_attr3 = 0; // char_attr saved for n_attr3

int n_skip = 0; // nr of chars to skip for 'nowrap'
int n_skip = 0; // nr of cells to skip for 'nowrap' or
// concealing
int skip_cells = 0; // nr of cells to skip for virtual text
// after the line, when w_skipcol is
// larger than the text length

int fromcol_prev = -2; // start of inverting after cursor
int noinvcur = FALSE; // don't invert the cursor
Expand Down Expand Up @@ -1504,6 +1508,11 @@ win_line(
n_skip = v - wlv.vcol;
}

// If there the text doesn't reach to the desired column, need to skip
// "skip_cells" cells when virtual text follows.
if (!wp->w_p_wrap && v > wlv.vcol)
skip_cells = v - wlv.vcol;

// Adjust for when the inverted text is before the screen,
// and when the start of the inverted text is before the screen.
if (wlv.tocol <= wlv.vcol)
Expand Down Expand Up @@ -1897,10 +1906,20 @@ win_line(
int tpi = text_prop_idxs[pi];
textprop_T *tp = &text_props[tpi];
proptype_T *pt = text_prop_type_by_id(
wp->w_buffer, tp->tp_type);

if (pt != NULL && (pt->pt_hl_id > 0
|| tp->tp_id < 0) && tp->tp_id != -MAXCOL)
wp->w_buffer, tp->tp_type);

// Only use a text property that can be displayed.
// Skip "after" properties when wrap is off and at the
// end of the window.
if (pt != NULL
&& (pt->pt_hl_id > 0 || tp->tp_id < 0)
&& tp->tp_id != -MAXCOL
&& !(tp->tp_id < 0
&& !wp->w_p_wrap
&& (tp->tp_flags & (TP_FLAG_ALIGN_RIGHT
| TP_FLAG_ALIGN_ABOVE
| TP_FLAG_ALIGN_BELOW)) == 0
&& wlv.col >= wp->w_width))
{
if (pt->pt_hl_id > 0)
used_attr = syn_id2attr(pt->pt_hl_id);
Expand Down Expand Up @@ -2015,6 +2034,30 @@ win_line(
}
}

// If the text didn't reach until the first window
// column we need to skip cells.
if (skip_cells > 0)
{
if (wlv.n_extra > skip_cells)
{
wlv.n_extra -= skip_cells;
wlv.p_extra += skip_cells;
n_attr_skip -= skip_cells;
if (n_attr_skip < 0)
n_attr_skip = 0;
skip_cells = 0;
}
else
{
// the whole text is left of the window, drop
// it and advance to the next one
skip_cells -= wlv.n_extra;
wlv.n_extra = 0;
n_attr_skip = 0;
bail_out = TRUE;
}
}

// If another text prop follows the condition below at
// the last window column must know.
// If this is an "above" text prop and 'nowrap' the we
Expand Down
6 changes: 3 additions & 3 deletions src/testdir/dumps/Test_text_after_nowrap_1.dump
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
|f+0&#ffffff0|i|r|s|t| |l|i|n|e| @1|a+0&#ffd7ff255|f|t|e|r| |t|h|e| |t|e|x|t| |a|f|t|e|r| |t|h|e| |t|e|x|t| |a|f|t|e|r| |t|h|e| |t|e|x|t| |a|f|t
|s+0&#ffffff0|e|c|o|n|d| >l|i|n|e| |s|e|c|o|n|d| |l|i|n|e| |s|e|c|o|n|d| |l|i|n|e| |s|e|c|o|n|d| |l|i|n|e| |s|e|c|o|n|d| |l|i|n|e|
|f+0&#ffffff0|i|r|s|t| |l|i|n|e| @1|r+0&#ffd7ff255|i|g|h|t| |a|f|t|e|r| |t|h|e| |t|e|x|t| |r|i|g|h|t| |a|f|t|e|r| |t|h|e| |t|e|x|t| |r|i|g|h|t|
|0+0&#ffffff0| >1| |2| |3| |4| |5| |6| |7| |8| |9| |1|0| |1@1| |1|2| |1|3| |1|4| |1|5| |1|6| |1|7| |1|8| |1|9| |2|0| |2|1| |2@1| |2
|t|h|i|r|d| @54
|f|o|u|r|t|h| @53
|~+0#4040ff13&| @58
|~| @58
|~| @58
| +0#0000000&@41|2|,|8| @10|A|l@1|
| +0#0000000&@41|2|,|3| @10|A|l@1|
8 changes: 8 additions & 0 deletions src/testdir/dumps/Test_text_after_nowrap_2.dump
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
| +0&#ffd7ff255|r|i|g|h|t| |a|f|t|e|r| |t|h|e| | +0&#ffffff0@2|i+0&#ffd7ff255|n| |t|h|e| |m|i|d@1|l|e| |i|n| |t|h|e| |m|i|d@1|l|e| |i|n| |t|h|e| |m|i|d@1|l
|2+0&#ffffff0|1| |2@1| |2|3| |2|4| |2|5| |2|6| |2|7| |2|8| |2|9| |3|0| >3|1| |3|2| |3@1| |3|4| |3|5| |3|6| |3|7| |3|8| |3|9| |4|0|
@60
@60
|~+0#4040ff13&| @58
|~| @58
|~| @58
| +0#0000000&@41|2|,|8|4| @9|A|l@1|
8 changes: 8 additions & 0 deletions src/testdir/dumps/Test_text_after_nowrap_3.dump
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
|h+0&#ffd7ff255|e| |m|i|d@1|l|e| | +0&#ffffff0|t+0&#ffd7ff255|h|e| |l|a|s|t| |o|n|e| |t|h|e| |l|a|s|t| |o|n|e| |t|h|e| |l|a|s|t| |o|n|e| | +0&#ffffff0@9
|4|3| |4@1| |4|5| |4|6| |4|7| |4|8| |4|9| |5|0| |5|1| |5|2| >5|3| |5|4| |5@1| |5|6| |5|7| |5|8| |5|9| |6|0| |6|1| |6|2|
@60
@60
|~+0#4040ff13&| @58
|~| @58
|~| @58
| +0#0000000&@41|2|,|1|5|0| @8|A|l@1|
8 changes: 8 additions & 0 deletions src/testdir/dumps/Test_text_after_nowrap_4.dump
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
| +0&#ffffff0@59
|9| |7|0| |7|1| |7|2| |7|3| |7|4| |7|5| |7|6| |7@1| |7|8| |7>9| @28
@60
@60
|~+0#4040ff13&| @58
|~| @58
|~| @58
| +0#0000000&@41|2|,|2@1|9| @8|A|l@1|
32 changes: 23 additions & 9 deletions src/testdir/test_textprop.vim
Original file line number Diff line number Diff line change
Expand Up @@ -3214,30 +3214,44 @@ endfunc
func Test_text_after_nowrap()
CheckRunVimInTerminal

" FIXME: the second property causes a hang
let lines =<< trim END
vim9script
setline(1, ['first line', 'second line '->repeat(50), 'third', 'fourth'])
setline(1, ['first line', range(80)->join(' '), 'third', 'fourth'])
set nowrap
prop_type_add('theprop', {highlight: 'DiffChange'})
prop_add(1, 0, {
type: 'theprop',
text: 'after the text '->repeat(5),
text: 'right after the text '->repeat(3),
text_align: 'after',
text_padding_left: 2,
})
#prop_add(1, 0, {
# type: 'theprop',
# text: 'after the text '->repeat(5),
# text_align: 'after',
# text_padding_left: 2,
#})
prop_add(1, 0, {
type: 'theprop',
text: 'in the middle '->repeat(4),
text_align: 'after',
text_padding_left: 3,
})
prop_add(1, 0, {
type: 'theprop',
text: 'the last one '->repeat(3),
text_align: 'after',
text_padding_left: 1,
})
normal 2Gw
END
call writefile(lines, 'XTextAfterNowrap', 'D')
let buf = RunVimInTerminal('-S XTextAfterNowrap', #{rows: 8, cols: 60})
call VerifyScreenDump(buf, 'Test_text_after_nowrap_1', {})

call term_sendkeys(buf, "30w")
call VerifyScreenDump(buf, 'Test_text_after_nowrap_2', {})

call term_sendkeys(buf, "22w")
call VerifyScreenDump(buf, 'Test_text_after_nowrap_3', {})

call term_sendkeys(buf, "$")
call VerifyScreenDump(buf, 'Test_text_after_nowrap_4', {})

call StopVimInTerminal(buf)
endfunc

Expand Down
2 changes: 2 additions & 0 deletions src/version.c
Original file line number Diff line number Diff line change
Expand Up @@ -699,6 +699,8 @@ static char *(features[]) =

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

0 comments on commit cd10541

Please sign in to comment.