patch 9.0.1731: blockwise Visual highlight not working with virtual text

Commit: 
https://github.com/vim/vim/commit/6e940d9a1d4ff122aad1b0821c784a60b507d45c
Author: zeertzjq <[email protected]>
Date:   Thu Aug 17 23:21:40 2023 +0200

    patch 9.0.1731: blockwise Visual highlight not working with virtual text
    
    Problem: blockwise Visual highlight not working with virtual text
    Solution: Reset the correct variable at the end of virtual selection and
              Check for double-width char inside virtual text.
    
    closes: #12606
    
    Signed-off-by: Christian Brabandt <[email protected]>
    Co-authored-by: zeertzjq <[email protected]>

diff --git a/src/drawline.c b/src/drawline.c
index 18ae4bf76..99994d64c 100644
--- a/src/drawline.c
+++ b/src/drawline.c
@@ -145,7 +145,8 @@ typedef struct {
     int                n_attr_skip;    // chars to skip before using extra_attr
     int                c_extra;        // extra chars, all the same
     int                c_final;        // final char, mandatory if set
-    int                extra_for_textprop; // wlv.n_extra set for textprop
+    int                extra_for_textprop; // n_extra set for textprop
+    int                start_extra_for_textprop; // extra_for_textprop was 
just set
 
     // saved "extra" items for when draw_state becomes WL_LINE (again)
     int                saved_n_extra;
@@ -1939,20 +1940,6 @@ win_line(
 
        if (wlv.draw_state == WL_LINE && (area_highlighting || extra_check))
        {
-           // handle Visual or match highlighting in this line
-           if (wlv.vcol == wlv.fromcol
-                   || (has_mbyte && wlv.vcol + 1 == wlv.fromcol
-                                                           && wlv.n_extra == 0
-                       && (*mb_ptr2cells)(ptr) > 1)
-                   || ((int)vcol_prev == fromcol_prev
-                       && vcol_prev < wlv.vcol // not at margin
-                       && wlv.vcol < wlv.tocol))
-               area_attr = vi_attr;            // start highlighting
-           else if (area_attr != 0
-                   && (wlv.vcol == wlv.tocol
-                       || (noinvcur && (colnr_T)wlv.vcol == wp->w_virtcol)))
-               area_attr = 0;                  // stop highlighting
-
 #ifdef FEAT_PROP_POPUP
            if (text_props != NULL)
            {
@@ -2131,15 +2118,10 @@ win_line(
                            wlv.c_final = NUL;
                            wlv.n_extra = (int)STRLEN(p);
                            wlv.extra_for_textprop = TRUE;
+                           wlv.start_extra_for_textprop = TRUE;
                            wlv.extra_attr = hl_combine_attr(wlv.win_attr,
                                                                    used_attr);
                            n_attr = mb_charlen(p);
-                           // restore search_attr and area_attr when n_extra
-                           // is down to zero
-                           saved_search_attr = search_attr;
-                           saved_area_attr = area_attr;
-                           search_attr = 0;
-                           area_attr = 0;
                            text_prop_attr = 0;
                            text_prop_attr_comb = 0;
                            if (*ptr == NUL)
@@ -2258,8 +2240,40 @@ win_line(
                    // Or when not wrapping and at the rightmost column.
                    text_prop_follows = TRUE;
            }
+
+           if (wlv.start_extra_for_textprop)
+           {
+               wlv.start_extra_for_textprop = FALSE;
+               // restore search_attr and area_attr when n_extra
+               // is down to zero
+               saved_search_attr = search_attr;
+               saved_area_attr = area_attr;
+               search_attr = 0;
+               area_attr = 0;
+           }
 #endif
 
+           int *area_attr_p =
+#ifdef FEAT_PROP_POPUP
+               wlv.extra_for_textprop ? &saved_area_attr :
+#endif
+                                                           &area_attr;
+
+           // handle Visual or match highlighting in this line
+           if (wlv.vcol == wlv.fromcol
+                   || (has_mbyte && wlv.vcol + 1 == wlv.fromcol
+                       && ((wlv.n_extra == 0 && (*mb_ptr2cells)(ptr) > 1)
+                           || (wlv.n_extra > 0 && wlv.p_extra != NULL
+                               && (*mb_ptr2cells)(wlv.p_extra) > 1)))
+                   || ((int)vcol_prev == fromcol_prev
+                       && vcol_prev < wlv.vcol // not at margin
+                       && wlv.vcol < wlv.tocol))
+               *area_attr_p = vi_attr;         // start highlighting
+           else if (*area_attr_p != 0
+                   && (wlv.vcol == wlv.tocol
+                       || (noinvcur && (colnr_T)wlv.vcol == wp->w_virtcol)))
+               *area_attr_p = 0;               // stop highlighting
+
 #ifdef FEAT_SEARCH_EXTRA
            if (wlv.n_extra == 0)
            {
diff --git a/src/testdir/dumps/Test_prop_inserts_text_visual_block_1.dump 
b/src/testdir/dumps/Test_prop_inserts_text_visual_block_1.dump
new file mode 100644
index 000000000..ce82e3958
--- /dev/null
+++ b/src/testdir/dumps/Test_prop_inserts_text_visual_block_1.dump
@@ -0,0 +1,6 @@
+>1+0&#ffffff0|2|3|4|5|6|7|8|9| @50
+|1|-+0#e000e06&|口*&|-+&|2+0#0000000&|3|4|5|6|7|8|9| @46
+|1|2|3|4|5|6|7|8|9| @50
+|~+0#4040ff13&| @58
+|~| @58
+| +0#0000000&@41|1|,|1| @10|A|l@1| 
diff --git a/src/testdir/dumps/Test_prop_inserts_text_visual_block_2.dump 
b/src/testdir/dumps/Test_prop_inserts_text_visual_block_2.dump
new file mode 100644
index 000000000..4fe696aa5
--- /dev/null
+++ b/src/testdir/dumps/Test_prop_inserts_text_visual_block_2.dump
@@ -0,0 +1,6 @@
+|1+0&#e0e0e08|2|3+0&#ffffff0|4|5|6|7|8|9| @50
+|1+0&#e0e0e08|-+0#e000e06#ffffff0|口*&|-+&|2+0#0000000&|3|4|5|6|7|8|9| @46
+|1+0&#e0e0e08>2+0&#ffffff0|3|4|5|6|7|8|9| @50
+|~+0#4040ff13&| @58
+|~| @58
+|-+2#0000000&@1| |V|I|S|U|A|L| |B|L|O|C|K| |-@1| +0&&@13|3|x|2| @6|3|,|2| 
@10|A|l@1| 
diff --git a/src/testdir/dumps/Test_prop_inserts_text_visual_block_3.dump 
b/src/testdir/dumps/Test_prop_inserts_text_visual_block_3.dump
new file mode 100644
index 000000000..27820c1f8
--- /dev/null
+++ b/src/testdir/dumps/Test_prop_inserts_text_visual_block_3.dump
@@ -0,0 +1,6 @@
+|1+0&#e0e0e08|2|3|4+0&#ffffff0|5|6|7|8|9| @50
+|1+0&#e0e0e08|-+0#e000e06#ffffff0|口*&|-+&|2+0#0000000&|3|4|5|6|7|8|9| @46
+|1+0&#e0e0e08|2>3+0&#ffffff0|4|5|6|7|8|9| @50
+|~+0#4040ff13&| @58
+|~| @58
+|-+2#0000000&@1| |V|I|S|U|A|L| |B|L|O|C|K| |-@1| +0&&@13|3|x|3| @6|3|,|3| 
@10|A|l@1| 
diff --git a/src/testdir/dumps/Test_prop_inserts_text_visual_block_4.dump 
b/src/testdir/dumps/Test_prop_inserts_text_visual_block_4.dump
new file mode 100644
index 000000000..8db2dd2bd
--- /dev/null
+++ b/src/testdir/dumps/Test_prop_inserts_text_visual_block_4.dump
@@ -0,0 +1,6 @@
+|1+0&#e0e0e08|2|3|4|5|6|7|8+0&#ffffff0|9| @50
+|1+0&#e0e0e08|-+0#e000e06#ffffff0|口*&|-+&|2+0#0000000#e0e0e08|3|4+0&#ffffff0|5|6|7|8|9|
 @46
+|1+0&#e0e0e08|2|3|4|5|6>7+0&#ffffff0|8|9| @50
+|~+0#4040ff13&| @58
+|~| @58
+|-+2#0000000&@1| |V|I|S|U|A|L| |B|L|O|C|K| |-@1| +0&&@13|3|x|7| @6|3|,|7| 
@10|A|l@1| 
diff --git a/src/testdir/dumps/Test_prop_inserts_text_visual_block_5.dump 
b/src/testdir/dumps/Test_prop_inserts_text_visual_block_5.dump
new file mode 100644
index 000000000..92418cc9e
--- /dev/null
+++ b/src/testdir/dumps/Test_prop_inserts_text_visual_block_5.dump
@@ -0,0 +1,6 @@
+|1+0&#ffffff0|2+0&#e0e0e08|3|4|5|6|7|8+0&#ffffff0|9| @50
+|1|-+0#e000e06&|口*&|-+&|2+0#0000000#e0e0e08|3|4+0&#ffffff0|5|6|7|8|9| @46
+|1>2|3+0&#e0e0e08|4|5|6|7|8+0&#ffffff0|9| @50
+|~+0#4040ff13&| @58
+|~| @58
+|-+2#0000000&@1| |V|I|S|U|A|L| |B|L|O|C|K| |-@1| +0&&@13|3|x|6| @6|3|,|2| 
@10|A|l@1| 
diff --git a/src/testdir/dumps/Test_prop_inserts_text_visual_block_6.dump 
b/src/testdir/dumps/Test_prop_inserts_text_visual_block_6.dump
new file mode 100644
index 000000000..78ba81de2
--- /dev/null
+++ b/src/testdir/dumps/Test_prop_inserts_text_visual_block_6.dump
@@ -0,0 +1,6 @@
+|1+0&#ffffff0|2|3+0&#e0e0e08|4|5|6|7|8+0&#ffffff0|9| @50
+|1|-+0#e000e06&|口*&|-+&|2+0#0000000#e0e0e08|3|4+0&#ffffff0|5|6|7|8|9| @46
+|1|2>3|4+0&#e0e0e08|5|6|7|8+0&#ffffff0|9| @50
+|~+0#4040ff13&| @58
+|~| @58
+|-+2#0000000&@1| |V|I|S|U|A|L| |B|L|O|C|K| |-@1| +0&&@13|3|x|5| @6|3|,|3| 
@10|A|l@1| 
diff --git a/src/testdir/dumps/Test_prop_inserts_text_visual_block_7.dump 
b/src/testdir/dumps/Test_prop_inserts_text_visual_block_7.dump
new file mode 100644
index 000000000..7011db771
--- /dev/null
+++ b/src/testdir/dumps/Test_prop_inserts_text_visual_block_7.dump
@@ -0,0 +1,6 @@
+|1+0&#ffffff0|2|3|4+0&#e0e0e08|5|6|7|8+0&#ffffff0|9| @50
+|1|-+0#e000e06&|口*&|-+&|2+0#0000000#e0e0e08|3|4+0&#ffffff0|5|6|7|8|9| @46
+|1|2|3>4|5+0&#e0e0e08|6|7|8+0&#ffffff0|9| @50
+|~+0#4040ff13&| @58
+|~| @58
+|-+2#0000000&@1| |V|I|S|U|A|L| |B|L|O|C|K| |-@1| +0&&@13|3|x|4| @6|3|,|4| 
@10|A|l@1| 
diff --git a/src/testdir/test_textprop.vim b/src/testdir/test_textprop.vim
index 67547f00a..d3a061d06 100644
--- a/src/testdir/test_textprop.vim
+++ b/src/testdir/test_textprop.vim
@@ -2602,6 +2602,33 @@ func Test_prop_inserts_text_highlight()
   call StopVimInTerminal(buf)
 endfunc
 
+func Test_prop_inserts_text_visual_block()
+  CheckRunVimInTerminal
+
+  let lines =<< trim END
+    call setline(1, repeat(['123456789'], 3))
+    call prop_type_add('theprop', #{highlight: 'Special'})
+    call prop_add(2, 2, {'type': 'theprop', 'text': '-口-'})
+  END
+  call writefile(lines, 'XscriptPropsVisualBlock', 'D')
+  let buf = RunVimInTerminal('-S XscriptPropsVisualBlock', #{rows: 6, cols: 
60})
+  call VerifyScreenDump(buf, 'Test_prop_inserts_text_visual_block_1', {})
+  call term_sendkeys(buf, "\<C-V>2jl")
+  call VerifyScreenDump(buf, 'Test_prop_inserts_text_visual_block_2', {})
+  call term_sendkeys(buf, "l")
+  call VerifyScreenDump(buf, 'Test_prop_inserts_text_visual_block_3', {})
+  call term_sendkeys(buf, "4l")
+  call VerifyScreenDump(buf, 'Test_prop_inserts_text_visual_block_4', {})
+  call term_sendkeys(buf, "Ol")
+  call VerifyScreenDump(buf, 'Test_prop_inserts_text_visual_block_5', {})
+  call term_sendkeys(buf, "l")
+  call VerifyScreenDump(buf, 'Test_prop_inserts_text_visual_block_6', {})
+  call term_sendkeys(buf, "l")
+  call VerifyScreenDump(buf, 'Test_prop_inserts_text_visual_block_7', {})
+
+  call StopVimInTerminal(buf)
+endfunc
+
 func Test_prop_add_with_text_fails()
   call prop_type_add('failing', #{highlight: 'ErrorMsg'})
   call assert_fails("call prop_add(1, 0, #{type: 'failing', text: 'X', 
end_lnum: 1})", 'E1305:')
diff --git a/src/version.c b/src/version.c
index 9a1709aa7..c20dedc0a 100644
--- a/src/version.c
+++ b/src/version.c
@@ -695,6 +695,8 @@ static char *(features[]) =
 
 static int included_patches[] =
 {   /* Add new patch number below this line */
+/**/
+    1731,
 /**/
     1730,
 /**/

-- 
-- 
You received this message from the "vim_dev" maillist.
Do not top-post! Type your reply below the text you are replying to.
For more information, visit http://www.vim.org/maillist.php

--- 
You received this message because you are subscribed to the Google Groups 
"vim_dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/vim_dev/E1qWkZA-006boP-6f%40256bit.org.

Raspunde prin e-mail lui