Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix wrong tablen with above virtual text #14178

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
3 changes: 3 additions & 0 deletions src/charset.c
Original file line number Diff line number Diff line change
Expand Up @@ -1212,6 +1212,9 @@ win_lbr_chartabsize(
# ifdef FEAT_PROP_POPUP
if (cts->cts_has_prop_with_text)
{
if (*s == TAB)
size = wp->w_buffer->b_p_ts;

int tab_size = size;
int charlen = *s == NUL ? 1 : mb_ptr2len(s);
int i;
Expand Down
12 changes: 10 additions & 2 deletions src/drawline.c
Original file line number Diff line number Diff line change
Expand Up @@ -3156,13 +3156,21 @@
{
int tab_len = 0;
long vcol_adjusted = wlv.vcol; // removed showbreak len
#ifdef FEAT_PROP_POPUP
// the lenght of above virtual text may add up to a number
// that is not a multiple of 'ts', adjust here to fix the
// calculation of tab_len
if (wlv.text_prop_above_count > 0)
vcol_adjusted -= (wp->w_width - win_col_off(wp))
* wlv.text_prop_above_count % wp->w_buffer->b_p_ts;
Comment on lines +3164 to +3165

Check failure

Code scanning / CodeQL

Multiplication result converted to larger type High

Multiplication result may overflow 'int' before it is converted to 'long'.
#endif
#ifdef FEAT_LINEBREAK
char_u *sbr = get_showbreak_value(wp);

// only adjust the tab_len, when at the first column
// after the showbreak value was drawn
if (*sbr != NUL && wlv.vcol == wlv.vcol_sbr && wp->w_p_wrap)
vcol_adjusted = wlv.vcol - MB_CHARLEN(sbr);
if (*sbr != NUL && vcol_adjusted == wlv.vcol_sbr && wp->w_p_wrap)
vcol_adjusted -= MB_CHARLEN(sbr);
#endif
// tab amount depends on current column
#ifdef FEAT_VARTABS
Expand Down
11 changes: 11 additions & 0 deletions src/testdir/dumps/Test_prop_above_tablen_1.dump
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
| +0&#ffffff0@15|a+0#4040ff13&|b|o|v|e| |1| +0#0000000&@10
@16|a+0#4040ff13&|b|o|v|e| |2| +0#0000000&@10
|<+0#0000e05&|-@5|>|<|-@5|>>o+0#0000000&|n|e| @14
@8|a+0#4040ff13&|b|o|v|e| |1| +0#0000000&@18
|<+0#0000e05&|-@5|>|t+0#0000000&|w|o| @22
@8|a+0#4040ff13&|b|o|v|e| |1| +0#0000000&@18
@3|<+0#0000e05&|-@2|>|3+0#0000000&|<+0#0000e05&|-@4|>|l+0#0000000&|i|n|e| |t|h|r|e@1|<+0#0000e05&|-@3|>|*+0#0000000&|<+0#0000e05&
|-@4|>|l+0#0000000&|i|n|e|<+0#0000e05&|-@1|>|t+0#0000000&|h|r|e@1| @14
@3|<+0#0000e05&|-@2|>|3+0#0000000&|<+0#0000e05&|-@4|>|l+0#0000000&|i|n|e| |t|h|r|e@1|<+0#0000e05&|-@3|>|*+0#0000000&|<+0#0000e05&
|-@4|>|l+0#0000000&|i|n|e|<+0#0000e05&|-@1|>|t+0#0000000&|h|r|e@1| @14
@17|1|,|3|-|8|5| @6|A|l@1|
11 changes: 11 additions & 0 deletions src/testdir/dumps/Test_prop_above_tablen_2.dump
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
| +0&#ffffff0@15|a+0#4040ff13&|b|o|v|e| |1| +0#0000000&@9
@16|a+0#4040ff13&|b|o|v|e| |2| +0#0000000&@9
|<+0#0000e05&|-@5|>|<|-@5|>>o+0#0000000&|n|e| @13
@8|a+0#4040ff13&|b|o|v|e| |1| +0#0000000&@17
|<+0#0000e05&|-@5|>|t+0#0000000&|w|o| @21
@8|a+0#4040ff13&|b|o|v|e| |1| +0#0000000&@17
@3|<+0#0000e05&|-@2|>|3+0#0000000&|<+0#0000e05&|-@4|>|l+0#0000000&|i|n|e| |t|h|r|e@1|<+0#0000e05&|-@3|>|*+0#0000000&
|<+0#0000e05&|-@4|>|l+0#0000000&|i|n|e|<+0#0000e05&|-@1|>|t+0#0000000&|h|r|e@1| @12
@3|<+0#0000e05&|-@2|>|3+0#0000000&|<+0#0000e05&|-@4|>|l+0#0000000&|i|n|e| |t|h|r|e@1|<+0#0000e05&|-@3|>|*+0#0000000&
|<+0#0000e05&|-@4|>|l+0#0000000&|i|n|e|<+0#0000e05&|-@1|>|t+0#0000000&|h|r|e@1| @12
@17|1|,|3|-|8|3| @5|A|l@1|
11 changes: 11 additions & 0 deletions src/testdir/dumps/Test_prop_above_tablen_3.dump
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
| +0&#ffffff0@15|a+0#4040ff13&|b|o|v|e| |1| +0#0000000&@8
@16|a+0#4040ff13&|b|o|v|e| |2| +0#0000000&@8
|<+0#0000e05&|-@5|>|<|-@5|>>o+0#0000000&|n|e| @12
@8|a+0#4040ff13&|b|o|v|e| |1| +0#0000000&@16
|<+0#0000e05&|-@5|>|t+0#0000000&|w|o| @20
@8|a+0#4040ff13&|b|o|v|e| |1| +0#0000000&@16
@3|<+0#0000e05&|-@2|>|3+0#0000000&|<+0#0000e05&|-@4|>|l+0#0000000&|i|n|e| |t|h|r|e@1|<+0#0000e05&|-@3|>
|*+0#0000000&|<+0#0000e05&|-@4|>|l+0#0000000&|i|n|e|<+0#0000e05&|-@1|>|t+0#0000000&|h|r|e@1| @10
@3|<+0#0000e05&|-@2|>|3+0#0000000&|<+0#0000e05&|-@4|>|l+0#0000000&|i|n|e| |t|h|r|e@1|<+0#0000e05&|-@3|>
|*+0#0000000&|<+0#0000e05&|-@4|>|l+0#0000000&|i|n|e|<+0#0000e05&|-@1|>|t+0#0000000&|h|r|e@1| @10
@16|1|,|3|-|8|1| @5|A|l@1|
11 changes: 11 additions & 0 deletions src/testdir/dumps/Test_prop_above_tablen_4.dump
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
| +0&#ffffff0@15|a+0#4040ff13&|b|o|v|e| |1| +0#0000000&@7
@16|a+0#4040ff13&|b|o|v|e| |2| +0#0000000&@7
|<+0#0000e05&|-@5|>|<|-@5|>>o+0#0000000&|n|e| @11
@8|a+0#4040ff13&|b|o|v|e| |1| +0#0000000&@15
|<+0#0000e05&|-@5|>|t+0#0000000&|w|o| @19
@8|a+0#4040ff13&|b|o|v|e| |1| +0#0000000&@15
@3|<+0#0000e05&|-@2|>|3+0#0000000&|<+0#0000e05&|-@4|>|l+0#0000000&|i|n|e| |t|h|r|e@1|<+0#0000e05&|-@3
|>|*+0#0000000&|<+0#0000e05&|-@4|>|l+0#0000000&|i|n|e|<+0#0000e05&|-@1|>|t+0#0000000&|h|r|e@1| @8
@3|<+0#0000e05&|-@2|>|3+0#0000000&|<+0#0000e05&|-@4|>|l+0#0000000&|i|n|e| |t|h|r|e@1|<+0#0000e05&|-@3
|>|*+0#0000000&|<+0#0000e05&|-@4|>|l+0#0000000&|i|n|e|<+0#0000e05&|-@1|>|t+0#0000000&|h|r|e@1| @8
@16|1|,|3|-|7|9| @4|A|l@1|
11 changes: 11 additions & 0 deletions src/testdir/dumps/Test_prop_above_tablen_5.dump
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
| +0&#ffffff0@15|a+0#4040ff13&|b|o|v|e| |1| +0#0000000&@6
@16|a+0#4040ff13&|b|o|v|e| |2| +0#0000000&@6
|<+0#0000e05&|-@5|>|<|-@5|>>o+0#0000000&|n|e| @10
@8|a+0#4040ff13&|b|o|v|e| |1| +0#0000000&@14
|<+0#0000e05&|-@5|>|t+0#0000000&|w|o| @18
@8|a+0#4040ff13&|b|o|v|e| |1| +0#0000000&@14
@3|<+0#0000e05&|-@2|>|3+0#0000000&|<+0#0000e05&|-@4|>|l+0#0000000&|i|n|e| |t|h|r|e@1|<+0#0000e05&|-@2
@1|>|*+0#0000000&|<+0#0000e05&|-@4|>|l+0#0000000&|i|n|e|<+0#0000e05&|-@1|>|t+0#0000000&|h|r|e@1| @6
@3|<+0#0000e05&|-@2|>|3+0#0000000&|<+0#0000e05&|-@4|>|l+0#0000000&|i|n|e| |t|h|r|e@1|<+0#0000e05&|-@2
@1|>|*+0#0000000&|<+0#0000e05&|-@4|>|l+0#0000000&|i|n|e|<+0#0000e05&|-@1|>|t+0#0000000&|h|r|e@1| @6
@15|1|,|3|-|7@1| @4|A|l@1|
11 changes: 11 additions & 0 deletions src/testdir/dumps/Test_prop_above_tablen_6.dump
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
| +0&#ffffff0@15|a+0#4040ff13&|b|o|v|e| |1| +0#0000000&@5
@16|a+0#4040ff13&|b|o|v|e| |2| +0#0000000&@5
|<+0#0000e05&|-@5|>|<|-@5|>>o+0#0000000&|n|e| @9
@8|a+0#4040ff13&|b|o|v|e| |1| +0#0000000&@13
|<+0#0000e05&|-@5|>|t+0#0000000&|w|o| @17
@8|a+0#4040ff13&|b|o|v|e| |1| +0#0000000&@13
@3|<+0#0000e05&|-@2|>|3+0#0000000&|<+0#0000e05&|-@4|>|l+0#0000000&|i|n|e| |t|h|r|e@1|<+0#0000e05&|-@1
@2|>|*+0#0000000&|<+0#0000e05&|-@4|>|l+0#0000000&|i|n|e|<+0#0000e05&|-@1|>|t+0#0000000&|h|r|e@1| @4
@3|<+0#0000e05&|-@2|>|3+0#0000000&|<+0#0000e05&|-@4|>|l+0#0000000&|i|n|e| |t|h|r|e@1|<+0#0000e05&|-@1
@2|>|*+0#0000000&|<+0#0000e05&|-@4|>|l+0#0000000&|i|n|e|<+0#0000e05&|-@1|>|t+0#0000000&|h|r|e@1| @4
@15|1|,|3|-|7|5| @3|A|l@1|
11 changes: 11 additions & 0 deletions src/testdir/dumps/Test_prop_above_tablen_7.dump
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
| +0&#ffffff0@15|a+0#4040ff13&|b|o|v|e| |1| +0#0000000&@4
@16|a+0#4040ff13&|b|o|v|e| |2| +0#0000000&@4
|<+0#0000e05&|-@5|>|<|-@5|>>o+0#0000000&|n|e| @8
@8|a+0#4040ff13&|b|o|v|e| |1| +0#0000000&@12
|<+0#0000e05&|-@5|>|t+0#0000000&|w|o| @16
@8|a+0#4040ff13&|b|o|v|e| |1| +0#0000000&@12
@3|<+0#0000e05&|-@2|>|3+0#0000000&|<+0#0000e05&|-@4|>|l+0#0000000&|i|n|e| |t|h|r|e@1|<+0#0000e05&|-
@3|>|*+0#0000000&|<+0#0000e05&|-@4|>|l+0#0000000&|i|n|e|<+0#0000e05&|-@1|>|t+0#0000000&|h|r|e@1| @2
@3|<+0#0000e05&|-@2|>|3+0#0000000&|<+0#0000e05&|-@4|>|l+0#0000000&|i|n|e| |t|h|r|e@1|<+0#0000e05&|-
@3|>|*+0#0000000&|<+0#0000e05&|-@4|>|l+0#0000000&|i|n|e|<+0#0000e05&|-@1|>|t+0#0000000&|h|r|e@1| @2
@14|1|,|3|-|7|3| @3|A|l@1|
32 changes: 32 additions & 0 deletions src/testdir/test_textprop.vim
Original file line number Diff line number Diff line change
Expand Up @@ -3638,6 +3638,38 @@ func Test_prop_above_with_indent()
call prop_type_delete('indented')
endfunc

func Test_prop_above_tablen()
CheckRunVimInTerminal

let lines =<< trim END
vim9script
[
"\t\tone",
"\ttwo",
" \t3\tline three\t*\tline\tthree",
" \t3\tline three\t*\tline\tthree",
]->setline(1)
prop_type_add('above', {highlight: 'NonText'})
prop_add(1, 0, { text: 'above 1', type: 'above', text_align: 'above', text_padding_left: 16, })
prop_add(1, 0, { text: 'above 2', type: 'above', text_align: 'above', text_padding_left: 16, })
prop_add(2, 0, { text: 'above 1', type: 'above', text_align: 'above', text_padding_left: 8, })
prop_add(3, 0, { text: 'above 1', type: 'above', text_align: 'above', text_padding_left: 8, })
set list listchars=tab:<->
END
call writefile(lines, 'XscriptPropAboveTab', 'D')
let buf = RunVimInTerminal('-S XscriptPropAboveTab', #{cols: 34, rows: 11})
call term_sendkeys(buf, "w")
call VerifyScreenDump(buf, 'Test_prop_above_tablen_1', {})

"TODO: also test for cursor position
for width in range(33, 28, -1)
call term_sendkeys(buf, ":set columns="..width.."\<CR>")
call VerifyScreenDump(buf, 'Test_prop_above_tablen_'..(35-width), {})
endfor

call StopVimInTerminal(buf)
endfunc

func Test_prop_above_with_number()
CheckRunVimInTerminal

Expand Down