Skip to content

Commit ebd0e8b

Browse files
committed
patch 9.0.0466: virtual text wrong after adding line break after line
Problem: Virtual text wrong after adding line break after line. Solution: Pass an "eol" flag to where text properties are adjusted. (closes #11131)
1 parent e697d48 commit ebd0e8b

File tree

6 files changed

+60
-12
lines changed

6 files changed

+60
-12
lines changed

src/change.c

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1404,12 +1404,19 @@ open_line(
14041404
int vreplace_mode;
14051405
int did_append; // appended a new line
14061406
int saved_pi = curbuf->b_p_pi; // copy of preserveindent setting
1407+
#ifdef FEAT_PROP_POPUP
1408+
int at_eol; // cursor after last character
1409+
#endif
14071410

14081411
// make a copy of the current line so we can mess with it
14091412
saved_line = vim_strsave(ml_get_curline());
14101413
if (saved_line == NULL) // out of memory!
14111414
return FALSE;
14121415

1416+
#ifdef FEAT_PROP_POPUP
1417+
at_eol = curwin->w_cursor.col >= (int)STRLEN(saved_line);
1418+
#endif
1419+
14131420
if (State & VREPLACE_FLAG)
14141421
{
14151422
// With MODE_VREPLACE we make a copy of the next line, which we will be
@@ -2133,7 +2140,7 @@ open_line(
21332140
if ((State & MODE_INSERT) && (State & VREPLACE_FLAG) == 0)
21342141
// Properties after the split move to the next line.
21352142
adjust_props_for_split(curwin->w_cursor.lnum, curwin->w_cursor.lnum,
2136-
curwin->w_cursor.col + 1, 0);
2143+
curwin->w_cursor.col + 1, 0, at_eol);
21372144
#endif
21382145
}
21392146
else

src/proto/textprop.pro

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,6 @@ void f_prop_type_list(typval_T *argvars, typval_T *rettv);
2222
void clear_global_prop_types(void);
2323
void clear_buf_prop_types(buf_T *buf);
2424
int adjust_prop_columns(linenr_T lnum, colnr_T col, int bytes_added, int flags);
25-
void adjust_props_for_split(linenr_T lnum_props, linenr_T lnum_top, int kept, int deleted);
25+
void adjust_props_for_split(linenr_T lnum_props, linenr_T lnum_top, int kept, int deleted, int at_eol);
2626
void prepend_joined_props(char_u *new_props, int propcount, int *props_remaining, linenr_T lnum, int last_line, long col, int removed);
2727
/* vim: set ft=c : */
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
|o+0&#ffffff0|n|e| |o|n|e| |o|n|e| @63
2+
|t|w|o| |t|w|o| |t|w|o| @63
3+
@3|└+2&&|─| |V|i|r|t|u|a|l| |t|e|x|t| |b|e|l|o|w| |t|h|e| |2|n|d| |l|i|n|e| +0&&@37
4+
|x@1> @72
5+
|t|h|r|e@1| |t|h|r|e@1| |t|h|r|e@1| @57
6+
|~+0#4040ff13&| @73
7+
|~| @73
8+
|-+2#0000000&@1| |I|N|S|E|R|T| |-@1| +0&&@44|3|,|3| @10|A|l@1|

src/testdir/test_textprop.vim

Lines changed: 24 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2908,6 +2908,29 @@ func Test_prop_above_with_indent()
29082908
call prop_type_delete('indented')
29092909
endfunc
29102910

2911+
func Test_prop_below_split_line()
2912+
CheckRunVimInTerminal
2913+
2914+
let lines =<< trim END
2915+
vim9script
2916+
setline(1, ['one one one', 'two two two', 'three three three'])
2917+
prop_type_add('test', {highlight: 'ModeMsg'})
2918+
prop_add(2, 0, {
2919+
text: '└─ Virtual text below the 2nd line',
2920+
type: 'test',
2921+
text_align: 'below',
2922+
text_padding_left: 3
2923+
})
2924+
END
2925+
call writefile(lines, 'XscriptPropBelowSpitLine', 'D')
2926+
let buf = RunVimInTerminal('-S XscriptPropBelowSpitLine', #{rows: 8})
2927+
call term_sendkeys(buf, "2GA\<CR>xx")
2928+
call VerifyScreenDump(buf, 'Test_prop_below_split_line_1', {})
2929+
2930+
call term_sendkeys(buf, "\<Esc>")
2931+
call StopVimInTerminal(buf)
2932+
endfunc
2933+
29112934
func Test_props_with_text_override()
29122935
CheckRunVimInTerminal
29132936

@@ -2920,7 +2943,7 @@ func Test_props_with_text_override()
29202943
hi CursorLine cterm=underline ctermbg=lightgrey
29212944
set cursorline
29222945
END
2923-
call writefile(lines, 'XscriptPropsOverride')
2946+
call writefile(lines, 'XscriptPropsOverride', 'D')
29242947
let buf = RunVimInTerminal('-S XscriptPropsOverride', #{rows: 6, cols: 60})
29252948
call VerifyScreenDump(buf, 'Test_prop_with_text_override_1', {})
29262949

@@ -2929,7 +2952,6 @@ func Test_props_with_text_override()
29292952
call VerifyScreenDump(buf, 'Test_prop_with_text_override_2', {})
29302953

29312954
call StopVimInTerminal(buf)
2932-
call delete('XscriptPropsOverride')
29332955
endfunc
29342956

29352957
func Test_props_with_text_CursorMoved()

src/textprop.c

Lines changed: 17 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2232,13 +2232,15 @@ adjust_prop_columns(
22322232
* "lnum_top" is the top line.
22332233
* "kept" is the number of bytes kept in the first line, while
22342234
* "deleted" is the number of bytes deleted.
2235+
* "at_eol" is true if the split is after the end of the line.
22352236
*/
22362237
void
22372238
adjust_props_for_split(
2238-
linenr_T lnum_props,
2239-
linenr_T lnum_top,
2240-
int kept,
2241-
int deleted)
2239+
linenr_T lnum_props,
2240+
linenr_T lnum_top,
2241+
int kept,
2242+
int deleted,
2243+
int at_eol)
22422244
{
22432245
char_u *props;
22442246
int count;
@@ -2276,9 +2278,16 @@ adjust_props_for_split(
22762278
// a text prop "above" behaves like it is on the first text column
22772279
prop_col = (prop.tp_flags & TP_FLAG_ALIGN_ABOVE) ? 1 : prop.tp_col;
22782280

2279-
cont_prev = prop_col != MAXCOL && prop_col + !start_incl <= kept;
2280-
cont_next = prop_col != MAXCOL
2281-
&& skipped <= prop_col + prop.tp_len - !end_incl;
2281+
if (prop_col == MAXCOL)
2282+
{
2283+
cont_prev = at_eol;
2284+
cont_next = !at_eol;
2285+
}
2286+
else
2287+
{
2288+
cont_prev = prop_col + !start_incl <= kept;
2289+
cont_next = skipped <= prop_col + prop.tp_len - !end_incl;
2290+
}
22822291
// when a prop has text it is never copied
22832292
if (prop.tp_id < 0 && cont_next)
22842293
cont_prev = FALSE;
@@ -2297,7 +2306,7 @@ adjust_props_for_split(
22972306

22982307
// Only add the property to the next line if the length is bigger than
22992308
// zero.
2300-
if ((cont_next || prop_col == MAXCOL) && ga_grow(&nextprop, 1) == OK)
2309+
if (cont_next && ga_grow(&nextprop, 1) == OK)
23012310
{
23022311
textprop_T *p = ((textprop_T *)nextprop.ga_data) + nextprop.ga_len;
23032312

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+
466,
706708
/**/
707709
465,
708710
/**/

0 commit comments

Comments
 (0)