0
0
mirror of https://github.com/vim/vim.git synced 2025-10-16 07:24:23 -04:00

patch 9.1.1796: Wrong cursor position with wrapped "after" virtual text and 'sbr'

Problem:  Wrong cursor position with wrapped "after" virtual text and
          'showbreak' (Ben Jackson)
Solution: Count size of 'showbreak' in wrapped "after" virtual text in
          line size (zeertzjq).

fixes: #18398
closes: #18400

Signed-off-by: zeertzjq <zeertzjq@outlook.com>
Signed-off-by: Christian Brabandt <cb@256bit.org>
This commit is contained in:
zeertzjq
2025-09-26 17:00:10 +00:00
committed by Christian Brabandt
parent 4aa4a56909
commit 3fc1f2a00e
17 changed files with 197 additions and 6 deletions

View File

@@ -918,8 +918,9 @@ win_linetabsize_cts(chartabsize_T *cts, colnr_T len)
// check for a virtual text at the end of a line or on an empty line
if (len == MAXCOL && cts->cts_has_prop_with_text && *cts->cts_ptr == NUL)
{
(void)win_lbr_chartabsize(cts, NULL);
vcol += cts->cts_cur_text_width;
int head = 0;
(void)win_lbr_chartabsize(cts, &head);
vcol += cts->cts_cur_text_width + head;
// when properties are above or below the empty line must also be
// counted
if (cts->cts_ptr == cts->cts_line && cts->cts_prop_lines > 0)
@@ -1325,7 +1326,8 @@ win_lbr_chartabsize(
(vcol + size) % (wp->w_width - col_off) + col_off,
&n_extra, &p, NULL, NULL, FALSE);
# ifdef FEAT_LINEBREAK
no_sbr = TRUE; // don't use 'showbreak' now
if (text_prop_no_showbreak(tp))
no_sbr = TRUE; // don't use 'showbreak' now
# endif
}
else

View File

@@ -829,6 +829,23 @@ text_prop_position(
return cells;
return (below && col_with_padding > win_col_off(wp) && !wp->w_p_wrap);
}
# if defined(FEAT_LINEBREAK) || defined(PROTO)
/*
* no 'showbreak' before "below" text property
* or after "above" or "right" text property
*/
int
text_prop_no_showbreak(textprop_T *tp)
{
int right = (tp->tp_flags & TP_FLAG_ALIGN_RIGHT);
int above = (tp->tp_flags & TP_FLAG_ALIGN_ABOVE);
int below = (tp->tp_flags & TP_FLAG_ALIGN_BELOW);
int wrap = tp->tp_col < MAXCOL || (tp->tp_flags & TP_FLAG_WRAP);
return (right || above || below || !wrap);
}
# endif
#endif
/*
@@ -2258,10 +2275,8 @@ win_line(
// don't combine char attr after EOL
text_prop_flags &= ~PT_FLAG_COMBINE;
# ifdef FEAT_LINEBREAK
if (above || below || right || !wrap)
if (text_prop_no_showbreak(tp))
{
// no 'showbreak' before "below" text property
// or after "above" or "right" text property
wlv.need_showbreak = FALSE;
wlv.dont_use_showbreak = TRUE;
}

View File

@@ -1,4 +1,5 @@
/* drawline.c */
int text_prop_position(win_T *wp, textprop_T *tp, int vcol, int scr_col, int *n_extra, char_u **p_extra, int *n_attr, int *n_attr_skip, int do_skip);
int text_prop_no_showbreak(textprop_T *tp);
int win_line(win_T *wp, linenr_T lnum, int startrow, int endrow, int number_only, spellvars_T *spv);
/* vim: set ft=c : */

View File

@@ -0,0 +1,8 @@
> +8&#ffffff0@7|"| |1|2|3|4|5|6|7|8|9|0
|>+8#4040ff13&| |a+8#0000001#a8a8a8255@3|8|9|0| |1|2|3| |4|5|6| |7|8
|>+8#4040ff13#ffffff0| |9+8#0000001#a8a8a8255| +8#0000000#ffffff0@16
|f+0&&|o@1| @16
|b|a|r| @16
|~+0#4040ff13&| @18
|~| @18
| +0#0000000&@9|1|,|1| @2|A|l@1|

View File

@@ -0,0 +1,8 @@
| +0&#ffffff0@7|"| |1|2|3|4|5|6|7|8|9|0
|>+0#4040ff13&| |a+0#0000001#a8a8a8255@3|8|9|0| |1|2|3| |4|5|6| |7|8
|>+0#4040ff13#ffffff0| |9+0#0000001#a8a8a8255| +0#0000000#ffffff0@16
>f+8&&|o@1| @16
|b+0&&|a|r| @16
|~+0#4040ff13&| @18
|~| @18
| +0#0000000&@9|2|,|1| @2|A|l@1|

View File

@@ -0,0 +1,8 @@
| +0&#ffffff0@7|"| |1|2|3|4|5|6|7|8|9|0
|>+0#4040ff13&| |a+0#0000001#a8a8a8255@3|8|9|0| |1|2|3| |4|5|6| |7|8
|>+0#4040ff13#ffffff0| |9+0#0000001#a8a8a8255| +0#0000000#ffffff0@16
|f|o@1| @16
>b+8&&|a|r| @16
|~+0#4040ff13&| @18
|~| @18
| +0#0000000&@9|3|,|1| @2|A|l@1|

View File

@@ -0,0 +1,8 @@
> +8&#ffffff0@7|"| |1|2|3|4|5|6|7|8|9|a+8#0000001#a8a8a8255
|>+8#4040ff13#ffffff0| |a+8#0000001#a8a8a8255@2|8|9|0| |1|2|3| |4|5|6| |7|8|9
|f+0#0000000#ffffff0|o@1| @16
|b|a|r| @16
|~+0#4040ff13&| @18
|~| @18
|~| @18
| +0#0000000&@9|1|,|1| @2|A|l@1|

View File

@@ -0,0 +1,8 @@
| +0&#ffffff0@7|"| |1|2|3|4|5|6|7|8|9|a+0#0000001#a8a8a8255
|>+0#4040ff13#ffffff0| |a+0#0000001#a8a8a8255@2|8|9|0| |1|2|3| |4|5|6| |7|8|9
>f+8#0000000#ffffff0|o@1| @16
|b+0&&|a|r| @16
|~+0#4040ff13&| @18
|~| @18
|~| @18
| +0#0000000&@9|2|,|1| @2|A|l@1|

View File

@@ -0,0 +1,8 @@
| +0&#ffffff0@7|"| |1|2|3|4|5|6|7|8|9|a+0#0000001#a8a8a8255
|>+0#4040ff13#ffffff0| |a+0#0000001#a8a8a8255@2|8|9|0| |1|2|3| |4|5|6| |7|8|9
|f+0#0000000#ffffff0|o@1| @16
>b+8&&|a|r| @16
|~+0#4040ff13&| @18
|~| @18
|~| @18
| +0#0000000&@9|3|,|1| @2|A|l@1|

View File

@@ -0,0 +1,8 @@
> +8&#ffffff0@7|"| |1|2|3|4|5|6|7|8|9|$+8#4040ff13&
|>| |a+8#0000001#a8a8a8255@3|8|9|0| |1|2|3| |4|5|6| |7|8
|>+8#4040ff13#ffffff0| |9+8#0000001#a8a8a8255| +8#0000000#ffffff0@16
|f+0&&|o@1|$+0#4040ff13&| +0#0000000&@15
|b|a|r|$+0#4040ff13&| +0#0000000&@15
|~+0#4040ff13&| @18
|~| @18
| +0#0000000&@9|1|,|1| @2|A|l@1|

View File

@@ -0,0 +1,8 @@
| +0&#ffffff0@7|"| |1|2|3|4|5|6|7|8|9|$+0#4040ff13&
|>| |a+0#0000001#a8a8a8255@3|8|9|0| |1|2|3| |4|5|6| |7|8
|>+0#4040ff13#ffffff0| |9+0#0000001#a8a8a8255| +0#0000000#ffffff0@16
>f+8&&|o@1|$+8#4040ff13&| +8#0000000&@15
|b+0&&|a|r|$+0#4040ff13&| +0#0000000&@15
|~+0#4040ff13&| @18
|~| @18
| +0#0000000&@9|2|,|1| @2|A|l@1|

View File

@@ -0,0 +1,8 @@
| +0&#ffffff0@7|"| |1|2|3|4|5|6|7|8|9|$+0#4040ff13&
|>| |a+0#0000001#a8a8a8255@3|8|9|0| |1|2|3| |4|5|6| |7|8
|>+0#4040ff13#ffffff0| |9+0#0000001#a8a8a8255| +0#0000000#ffffff0@16
|f|o@1|$+0#4040ff13&| +0#0000000&@15
>b+8&&|a|r|$+8#4040ff13&| +8#0000000&@15
|~+0#4040ff13&| @18
|~| @18
| +0#0000000&@9|3|,|1| @2|A|l@1|

View File

@@ -0,0 +1,8 @@
> +8&#ffffff0@7|"| |1|2|3|4|5|6|7|8|$+8#4040ff13&|a+8#0000001#a8a8a8255
|>+8#4040ff13#ffffff0| |a+8#0000001#a8a8a8255@2|8|9|0| |1|2|3| |4|5|6| |7|8|9
|f+0#0000000#ffffff0|o@1|$+0#4040ff13&| +0#0000000&@15
|b|a|r|$+0#4040ff13&| +0#0000000&@15
|~+0#4040ff13&| @18
|~| @18
|~| @18
| +0#0000000&@9|1|,|1| @2|A|l@1|

View File

@@ -0,0 +1,8 @@
| +0&#ffffff0@7|"| |1|2|3|4|5|6|7|8|$+0#4040ff13&|a+0#0000001#a8a8a8255
|>+0#4040ff13#ffffff0| |a+0#0000001#a8a8a8255@2|8|9|0| |1|2|3| |4|5|6| |7|8|9
>f+8#0000000#ffffff0|o@1|$+8#4040ff13&| +8#0000000&@15
|b+0&&|a|r|$+0#4040ff13&| +0#0000000&@15
|~+0#4040ff13&| @18
|~| @18
|~| @18
| +0#0000000&@9|2|,|1| @2|A|l@1|

View File

@@ -0,0 +1,8 @@
| +0&#ffffff0@7|"| |1|2|3|4|5|6|7|8|$+0#4040ff13&|a+0#0000001#a8a8a8255
|>+0#4040ff13#ffffff0| |a+0#0000001#a8a8a8255@2|8|9|0| |1|2|3| |4|5|6| |7|8|9
|f+0#0000000#ffffff0|o@1|$+0#4040ff13&| +0#0000000&@15
>b+8&&|a|r|$+8#4040ff13&| +8#0000000&@15
|~+0#4040ff13&| @18
|~| @18
|~| @18
| +0#0000000&@9|3|,|1| @2|A|l@1|

View File

@@ -4264,6 +4264,81 @@ func Test_text_after_nowrap_list()
call StopVimInTerminal(buf)
endfunc
func Test_text_after_wrap_showbreak()
CheckScreendump
CheckRunVimInTerminal
let lines =<< trim END
set cursorline
set shiftwidth=4
set breakindent
set showbreak=>\
set breakindentopt=shift:2,min:64
call setline(1, [' " 1234567890', 'foo', 'bar'])
call prop_type_add('Test', {
\ 'highlight': 'Visual',
\ 'priority': 10,
\ 'combine': v:true,
\ })
call prop_add(1, 0, #{
\ type: 'Test',
\ bufnr: bufnr('%'),
\ text: 'aaaa890 123 456 789',
\ text_wrap: 'wrap',
\ text_align: 'after'
\ })
END
call writefile(lines, 'XTestAfterWrapShowbreak', 'D')
let buf = RunVimInTerminal('-S XTestAfterWrapShowbreak', #{rows: 8, cols: 20})
call VerifyScreenDump(buf, 'Test_text_after_wrap_showbreak_01', {})
call term_sendkeys(buf, 'j')
call VerifyScreenDump(buf, 'Test_text_after_wrap_showbreak_02', {})
call term_sendkeys(buf, 'j')
call VerifyScreenDump(buf, 'Test_text_after_wrap_showbreak_03', {})
call term_sendkeys(buf, 'k')
call VerifyScreenDump(buf, 'Test_text_after_wrap_showbreak_02', {})
call term_sendkeys(buf, 'k')
call VerifyScreenDump(buf, 'Test_text_after_wrap_showbreak_01', {})
call term_sendkeys(buf, '$x0')
call VerifyScreenDump(buf, 'Test_text_after_wrap_showbreak_04', {})
call term_sendkeys(buf, 'j')
call VerifyScreenDump(buf, 'Test_text_after_wrap_showbreak_05', {})
call term_sendkeys(buf, 'j')
call VerifyScreenDump(buf, 'Test_text_after_wrap_showbreak_06', {})
call term_sendkeys(buf, 'k')
call VerifyScreenDump(buf, 'Test_text_after_wrap_showbreak_05', {})
call term_sendkeys(buf, 'k')
call VerifyScreenDump(buf, 'Test_text_after_wrap_showbreak_04', {})
call term_sendkeys(buf, ":set list listchars=eol:$\<CR>")
call VerifyScreenDump(buf, 'Test_text_after_wrap_showbreak_07', {})
call term_sendkeys(buf, 'j')
call VerifyScreenDump(buf, 'Test_text_after_wrap_showbreak_08', {})
call term_sendkeys(buf, 'j')
call VerifyScreenDump(buf, 'Test_text_after_wrap_showbreak_09', {})
call term_sendkeys(buf, 'k')
call VerifyScreenDump(buf, 'Test_text_after_wrap_showbreak_08', {})
call term_sendkeys(buf, 'k')
call VerifyScreenDump(buf, 'Test_text_after_wrap_showbreak_07', {})
call term_sendkeys(buf, '$x0')
call VerifyScreenDump(buf, 'Test_text_after_wrap_showbreak_10', {})
call term_sendkeys(buf, 'j')
call VerifyScreenDump(buf, 'Test_text_after_wrap_showbreak_11', {})
call term_sendkeys(buf, 'j')
call VerifyScreenDump(buf, 'Test_text_after_wrap_showbreak_12', {})
call term_sendkeys(buf, 'k')
call VerifyScreenDump(buf, 'Test_text_after_wrap_showbreak_11', {})
call term_sendkeys(buf, 'k')
call VerifyScreenDump(buf, 'Test_text_after_wrap_showbreak_10', {})
call StopVimInTerminal(buf)
endfunc
func Test_text_below_nowrap()
CheckScreendump
CheckRunVimInTerminal

View File

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