patch 9.0.0466: virtual text wrong after adding line break after line v9.0.0466
authorBram Moolenaar <Bram@vim.org>
Wed, 14 Sep 2022 21:13:59 +0000 (22:13 +0100)
committerBram Moolenaar <Bram@vim.org>
Wed, 14 Sep 2022 21:13:59 +0000 (22:13 +0100)
Problem:    Virtual text wrong after adding line break after line.
Solution:   Pass an "eol" flag to where text properties are adjusted.
            (closes #11131)

src/change.c
src/proto/textprop.pro
src/testdir/dumps/Test_prop_below_split_line_1.dump [new file with mode: 0644]
src/testdir/test_textprop.vim
src/textprop.c
src/version.c

index b84dfad358cb21c61ff83576bd7ded6e213e8a2a..038f3c199fc6541af5dc6de7ed1d84f266a1127c 100644 (file)
@@ -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
index b3912c16ae30b6da9e2bdd9b9d425069c58f50a0..aa06e61f7650bf816d7721819a4cccad917e4cfc 100644 (file)
@@ -22,6 +22,6 @@ void f_prop_type_list(typval_T *argvars, typval_T *rettv);
 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 (file)
index 0000000..671fcea
--- /dev/null
@@ -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| 
index 0a4037b9ef0f7f8cee8153114e901ff448066fbe..8a80e5504fdcb94f1797b9ce4a2534f1772619d0 100644 (file)
@@ -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\<CR>xx")
+  call VerifyScreenDump(buf, 'Test_prop_below_split_line_1', {})
+
+  call term_sendkeys(buf, "\<Esc>")
+  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()
index ba21e751bff454ffa8edce66e9035d4420cdd8be..6e5c1447fff9b3b07ae0fa156a8fe4fa7de90884 100644 (file)
@@ -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;
 
index cea4b7387bd10254dc6e85464440d1601ad51aac..1aa99ae379cf3d1eed170fe44bb0250e99c03c83 100644 (file)
@@ -703,6 +703,8 @@ static char *(features[]) =
 
 static int included_patches[] =
 {   /* Add new patch number below this line */
+/**/
+    466,
 /**/
     465,
 /**/