# HG changeset patch # User Bram Moolenaar # Date 1663190103 -7200 # Node ID 6b658ef69e9348c4b145bde0be4400255703c647 # Parent 742a12140d60e1df942d3aac13e0db44287d8a73 patch 9.0.0466: virtual text wrong after adding line break after line Commit: https://github.com/vim/vim/commit/ebd0e8bb853cb744b60bf4f57011c4379ae4aaed Author: Bram Moolenaar Date: Wed Sep 14 22:13:59 2022 +0100 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) diff --git a/src/change.c b/src/change.c --- a/src/change.c +++ b/src/change.c @@ -1404,12 +1404,19 @@ open_line( int vreplace_mode; int did_append; // appended a new line int saved_pi = curbuf->b_p_pi; // copy of preserveindent setting +#ifdef FEAT_PROP_POPUP + int at_eol; // cursor after last character +#endif // make a copy of the current line so we can mess with it saved_line = vim_strsave(ml_get_curline()); if (saved_line == NULL) // out of memory! return FALSE; +#ifdef FEAT_PROP_POPUP + at_eol = curwin->w_cursor.col >= (int)STRLEN(saved_line); +#endif + if (State & VREPLACE_FLAG) { // With MODE_VREPLACE we make a copy of the next line, which we will be @@ -2133,7 +2140,7 @@ open_line( if ((State & MODE_INSERT) && (State & VREPLACE_FLAG) == 0) // Properties after the split move to the next line. adjust_props_for_split(curwin->w_cursor.lnum, curwin->w_cursor.lnum, - curwin->w_cursor.col + 1, 0); + curwin->w_cursor.col + 1, 0, at_eol); #endif } else diff --git a/src/proto/textprop.pro b/src/proto/textprop.pro --- a/src/proto/textprop.pro +++ b/src/proto/textprop.pro @@ -22,6 +22,6 @@ void f_prop_type_list(typval_T *argvars, void clear_global_prop_types(void); void clear_buf_prop_types(buf_T *buf); int adjust_prop_columns(linenr_T lnum, colnr_T col, int bytes_added, int flags); -void adjust_props_for_split(linenr_T lnum_props, linenr_T lnum_top, int kept, int deleted); +void adjust_props_for_split(linenr_T lnum_props, linenr_T lnum_top, int kept, int deleted, int at_eol); void prepend_joined_props(char_u *new_props, int propcount, int *props_remaining, linenr_T lnum, int last_line, long col, int removed); /* vim: set ft=c : */ diff --git a/src/testdir/dumps/Test_prop_below_split_line_1.dump b/src/testdir/dumps/Test_prop_below_split_line_1.dump new file mode 100644 --- /dev/null +++ b/src/testdir/dumps/Test_prop_below_split_line_1.dump @@ -0,0 +1,8 @@ +|o+0&#ffffff0|n|e| |o|n|e| |o|n|e| @63 +|t|w|o| |t|w|o| |t|w|o| @63 +@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 +|x@1> @72 +|t|h|r|e@1| |t|h|r|e@1| |t|h|r|e@1| @57 +|~+0#4040ff13&| @73 +|~| @73 +|-+2#0000000&@1| |I|N|S|E|R|T| |-@1| +0&&@44|3|,|3| @10|A|l@1| diff --git a/src/testdir/test_textprop.vim b/src/testdir/test_textprop.vim --- a/src/testdir/test_textprop.vim +++ b/src/testdir/test_textprop.vim @@ -2908,6 +2908,29 @@ func Test_prop_above_with_indent() call prop_type_delete('indented') endfunc +func Test_prop_below_split_line() + CheckRunVimInTerminal + + let lines =<< trim END + vim9script + setline(1, ['one one one', 'two two two', 'three three three']) + prop_type_add('test', {highlight: 'ModeMsg'}) + prop_add(2, 0, { + text: '└─ Virtual text below the 2nd line', + type: 'test', + text_align: 'below', + text_padding_left: 3 + }) + END + call writefile(lines, 'XscriptPropBelowSpitLine', 'D') + let buf = RunVimInTerminal('-S XscriptPropBelowSpitLine', #{rows: 8}) + call term_sendkeys(buf, "2GA\xx") + call VerifyScreenDump(buf, 'Test_prop_below_split_line_1', {}) + + call term_sendkeys(buf, "\") + call StopVimInTerminal(buf) +endfunc + func Test_props_with_text_override() CheckRunVimInTerminal @@ -2920,7 +2943,7 @@ func Test_props_with_text_override() hi CursorLine cterm=underline ctermbg=lightgrey set cursorline END - call writefile(lines, 'XscriptPropsOverride') + call writefile(lines, 'XscriptPropsOverride', 'D') let buf = RunVimInTerminal('-S XscriptPropsOverride', #{rows: 6, cols: 60}) call VerifyScreenDump(buf, 'Test_prop_with_text_override_1', {}) @@ -2929,7 +2952,6 @@ func Test_props_with_text_override() call VerifyScreenDump(buf, 'Test_prop_with_text_override_2', {}) call StopVimInTerminal(buf) - call delete('XscriptPropsOverride') endfunc func Test_props_with_text_CursorMoved() diff --git a/src/textprop.c b/src/textprop.c --- a/src/textprop.c +++ b/src/textprop.c @@ -2232,13 +2232,15 @@ adjust_prop_columns( * "lnum_top" is the top line. * "kept" is the number of bytes kept in the first line, while * "deleted" is the number of bytes deleted. + * "at_eol" is true if the split is after the end of the line. */ void adjust_props_for_split( - linenr_T lnum_props, - linenr_T lnum_top, - int kept, - int deleted) + linenr_T lnum_props, + linenr_T lnum_top, + int kept, + int deleted, + int at_eol) { char_u *props; int count; @@ -2276,9 +2278,16 @@ adjust_props_for_split( // a text prop "above" behaves like it is on the first text column prop_col = (prop.tp_flags & TP_FLAG_ALIGN_ABOVE) ? 1 : prop.tp_col; - cont_prev = prop_col != MAXCOL && prop_col + !start_incl <= kept; - cont_next = prop_col != MAXCOL - && skipped <= prop_col + prop.tp_len - !end_incl; + if (prop_col == MAXCOL) + { + cont_prev = at_eol; + cont_next = !at_eol; + } + else + { + cont_prev = prop_col + !start_incl <= kept; + cont_next = skipped <= prop_col + prop.tp_len - !end_incl; + } // when a prop has text it is never copied if (prop.tp_id < 0 && cont_next) cont_prev = FALSE; @@ -2297,7 +2306,7 @@ adjust_props_for_split( // Only add the property to the next line if the length is bigger than // zero. - if ((cont_next || prop_col == MAXCOL) && ga_grow(&nextprop, 1) == OK) + if (cont_next && ga_grow(&nextprop, 1) == OK) { textprop_T *p = ((textprop_T *)nextprop.ga_data) + nextprop.ga_len; diff --git a/src/version.c b/src/version.c --- a/src/version.c +++ b/src/version.c @@ -704,6 +704,8 @@ static char *(features[]) = static int included_patches[] = { /* Add new patch number below this line */ /**/ + 466, +/**/ 465, /**/ 464,