patch 9.2.0221: Visual selection drawn incorrectly with "autoselect"

Commit: 
https://github.com/vim/vim/commit/03e89ccf3349d7b820b19a7cee963b41bc4395a2
Author: zeertzjq <[email protected]>
Date:   Sun Mar 22 15:44:47 2026 +0000

    patch 9.2.0221: Visual selection drawn incorrectly with "autoselect"
    
    Problem:  Visual selection may be drawn incorrectly with "autoselect".
    Solution: Restore w_virtcol after getting clipboard selection
              (zeertzjq).
    
    fixes:  #19590
    closes: #19784
    
    Signed-off-by: zeertzjq <[email protected]>
    Signed-off-by: Christian Brabandt <[email protected]>

diff --git a/src/clipboard.c b/src/clipboard.c
index 7ed339689..0786f29cc 100644
--- a/src/clipboard.c
+++ b/src/clipboard.c
@@ -2102,6 +2102,7 @@ clip_get_selection(Clipboard_T *cbd)
     pos_T      old_cursor;
     pos_T      old_visual;
     int                old_visual_mode;
+    colnr_T    old_virtcol;
     colnr_T    old_curswant;
     int                old_set_curswant;
     pos_T      old_op_start, old_op_end;
@@ -2123,6 +2124,7 @@ clip_get_selection(Clipboard_T *cbd)
        old_y_previous = get_y_previous();
        old_y_current = get_y_current();
        old_cursor = curwin->w_cursor;
+       old_virtcol = curwin->w_virtcol;
        old_curswant = curwin->w_curswant;
        old_set_curswant = curwin->w_set_curswant;
        old_op_start = curbuf->b_op_start;
@@ -2143,7 +2145,8 @@ clip_get_selection(Clipboard_T *cbd)
        set_y_previous(old_y_previous);
        set_y_current(old_y_current);
        curwin->w_cursor = old_cursor;
-       changed_cline_bef_curs();   // need to update w_virtcol et al
+       curwin->w_virtcol = old_virtcol;
+       changed_cline_bef_curs();   // old w_virtcol et al. may be invalid
        curwin->w_curswant = old_curswant;
        curwin->w_set_curswant = old_set_curswant;
        curbuf->b_op_start = old_op_start;
diff --git a/src/testdir/dumps/Test_visual_block_hl_with_autoselect_1.dump 
b/src/testdir/dumps/Test_visual_block_hl_with_autoselect_1.dump
new file mode 100644
index 000000000..5b88c7584
--- /dev/null
+++ b/src/testdir/dumps/Test_visual_block_hl_with_autoselect_1.dump
@@ -0,0 +1,10 @@
+|a+0&#ffffff0@4| |a@9|(|a@8| |a@3|)| @42
+|{| @73
+@8|a+0#0000001#a8a8a8255|a+0#0000000#ffffff0@21|;| @42
+@8|a+0#0000001#a8a8a8255|a+0#0000000#ffffff0@21|;| @42
+@8|a+0#0000001#a8a8a8255|a+0#0000000#ffffff0@21|;| @42
+@8|a+0#0000001#a8a8a8255|a+0#0000000#ffffff0@21|;| @42
+@8>a@22|;| @42
+|}| @73
+|~+0#4040ff13&| @73
+|-+2#0000000&@1| |V|I|S|U|A|L| |B|L|O|C|K| |-@1| +0&&@28|5|x|1| @6|7|,|2|-|9| 
@8|A|l@1| 
diff --git a/src/testdir/dumps/Test_visual_block_hl_with_autoselect_2.dump 
b/src/testdir/dumps/Test_visual_block_hl_with_autoselect_2.dump
new file mode 100644
index 000000000..86b7ba8e4
--- /dev/null
+++ b/src/testdir/dumps/Test_visual_block_hl_with_autoselect_2.dump
@@ -0,0 +1,10 @@
+|a+0&#ffffff0@4| |a@9|(|a@8| |a@3|)| @42
+|{| @73
+@8|a+0#0000001#a8a8a8255@1|a+0#0000000#ffffff0@20|;| @42
+@8|a+0#0000001#a8a8a8255@1|a+0#0000000#ffffff0@20|;| @42
+@8|a+0#0000001#a8a8a8255@1|a+0#0000000#ffffff0@20|;| @42
+@8|a+0#0000001#a8a8a8255@1|a+0#0000000#ffffff0@20|;| @42
+@8|a+0#0000001#a8a8a8255>a+0#0000000#ffffff0@21|;| @42
+|}| @73
+|~+0#4040ff13&| @73
+|-+2#0000000&@1| |V|I|S|U|A|L| |B|L|O|C|K| |-@1| +0&&@28|5|x|2| 
@6|7|,|3|-|1|0| @7|A|l@1| 
diff --git a/src/testdir/dumps/Test_visual_block_hl_with_autoselect_3.dump 
b/src/testdir/dumps/Test_visual_block_hl_with_autoselect_3.dump
new file mode 100644
index 000000000..39e14eb4b
--- /dev/null
+++ b/src/testdir/dumps/Test_visual_block_hl_with_autoselect_3.dump
@@ -0,0 +1,10 @@
+|a+0&#ffffff0@4| |a@9|(|a@8| |a@3|)| @42
+|{| @73
+@8|a+0#0000001#a8a8a8255@2|a+0#0000000#ffffff0@19|;| @42
+@8|a+0#0000001#a8a8a8255@2|a+0#0000000#ffffff0@19|;| @42
+@8|a+0#0000001#a8a8a8255@2|a+0#0000000#ffffff0@19|;| @42
+@8|a+0#0000001#a8a8a8255@2|a+0#0000000#ffffff0@19|;| @42
+@8|a+0#0000001#a8a8a8255@1>a+0#0000000#ffffff0@20|;| @42
+|}| @73
+|~+0#4040ff13&| @73
+|-+2#0000000&@1| |V|I|S|U|A|L| |B|L|O|C|K| |-@1| +0&&@28|5|x|3| 
@6|7|,|4|-|1@1| @7|A|l@1| 
diff --git a/src/testdir/dumps/Test_visual_block_hl_with_autoselect_4.dump 
b/src/testdir/dumps/Test_visual_block_hl_with_autoselect_4.dump
new file mode 100644
index 000000000..99949550e
--- /dev/null
+++ b/src/testdir/dumps/Test_visual_block_hl_with_autoselect_4.dump
@@ -0,0 +1,10 @@
+|a+0&#ffffff0@4| |a@9|(|a@8| |a@3|)| @42
+|{| @73
+@8|a+0#0000001#a8a8a8255@3|a+0#0000000#ffffff0@18|;| @42
+@8|a+0#0000001#a8a8a8255@3|a+0#0000000#ffffff0@18|;| @42
+@8|a+0#0000001#a8a8a8255@3|a+0#0000000#ffffff0@18|;| @42
+@8|a+0#0000001#a8a8a8255@3|a+0#0000000#ffffff0@18|;| @42
+@8|a+0#0000001#a8a8a8255@2>a+0#0000000#ffffff0@19|;| @42
+|}| @73
+|~+0#4040ff13&| @73
+|-+2#0000000&@1| |V|I|S|U|A|L| |B|L|O|C|K| |-@1| +0&&@28|5|x|4| 
@6|7|,|5|-|1|2| @7|A|l@1| 
diff --git a/src/testdir/dumps/Test_visual_block_hl_with_autoselect_5.dump 
b/src/testdir/dumps/Test_visual_block_hl_with_autoselect_5.dump
new file mode 100644
index 000000000..f2e581bd9
--- /dev/null
+++ b/src/testdir/dumps/Test_visual_block_hl_with_autoselect_5.dump
@@ -0,0 +1,10 @@
+|a+0&#ffffff0@4| |a@9|(|a@8| |a@3|)| @42
+|{| @73
+@8|a+0#0000001#a8a8a8255@4|a+0#0000000#ffffff0@17|;| @42
+@8|a+0#0000001#a8a8a8255@4|a+0#0000000#ffffff0@17|;| @42
+@8|a+0#0000001#a8a8a8255@4|a+0#0000000#ffffff0@17|;| @42
+@8|a+0#0000001#a8a8a8255@4|a+0#0000000#ffffff0@17|;| @42
+@8|a+0#0000001#a8a8a8255@3>a+0#0000000#ffffff0@18|;| @42
+|}| @73
+|~+0#4040ff13&| @73
+|-+2#0000000&@1| |V|I|S|U|A|L| |B|L|O|C|K| |-@1| +0&&@28|5|x|5| 
@6|7|,|6|-|1|3| @7|A|l@1| 
diff --git a/src/testdir/samples/visual_block_hl.txt 
b/src/testdir/samples/visual_block_hl.txt
new file mode 100644
index 000000000..a912473f9
--- /dev/null
+++ b/src/testdir/samples/visual_block_hl.txt
@@ -0,0 +1,8 @@
+aaaaa aaaaaaaaaa(aaaaaaaaa aaaa)
+{
+       aaaaaaaaaaaaaaaaaaaaaaa;
+       aaaaaaaaaaaaaaaaaaaaaaa;
+       aaaaaaaaaaaaaaaaaaaaaaa;
+       aaaaaaaaaaaaaaaaaaaaaaa;
+       aaaaaaaaaaaaaaaaaaaaaaa;
+}
diff --git a/src/testdir/test_visual.vim b/src/testdir/test_visual.vim
index 361868d86..ba1922803 100644
--- a/src/testdir/test_visual.vim
+++ b/src/testdir/test_visual.vim
@@ -1618,6 +1618,37 @@ func Test_visual_hl_with_showbreak()
   call StopVimInTerminal(buf)
 endfunc
 
+" Test for https://github.com/vim/vim/issues/19590
+func Test_visual_block_hl_with_autoselect()
+  CheckScreendump
+
+  " "autoselect" is included in the default 'clipboard' if available.
+  " Redraw at the end is necessary due to 
https://github.com/vim/vim/issues/16620
+  let lines =<< trim END
+    set shortmess+=F
+    edit samples/visual_block_hl.txt
+    setlocal filetype=c syntax=c
+    exe "normal! 3gg0l\<C-V>4j"
+    redraw
+  END
+  call writefile(lines, 'XTest_visual_block_autoselect', 'D')
+
+  let buf = RunVimInTerminal('-S XTest_visual_block_autoselect', {'rows': 10})
+  call VerifyScreenDump(buf, 'Test_visual_block_hl_with_autoselect_1', {})
+  call term_sendkeys(buf, 'l')
+  call VerifyScreenDump(buf, 'Test_visual_block_hl_with_autoselect_2', {})
+  call term_sendkeys(buf, 'l')
+  call VerifyScreenDump(buf, 'Test_visual_block_hl_with_autoselect_3', {})
+  call term_sendkeys(buf, 'l')
+  call VerifyScreenDump(buf, 'Test_visual_block_hl_with_autoselect_4', {})
+  call term_sendkeys(buf, 'l')
+  call VerifyScreenDump(buf, 'Test_visual_block_hl_with_autoselect_5', {})
+
+  " clean up
+  call term_sendkeys(buf, "\<Esc>")
+  call StopVimInTerminal(buf)
+endfunc
+
 func Test_visual_highlight_when_using_a_clipboard_provider()
   " The test assumes different screen attributes will be used for Visual and 
for VisualNOS.
   CheckFeature clipboard_provider
diff --git a/src/version.c b/src/version.c
index f314e46b1..9f578f20e 100644
--- a/src/version.c
+++ b/src/version.c
@@ -734,6 +734,8 @@ static char *(features[]) =
 
 static int included_patches[] =
 {   /* Add new patch number below this line */
+/**/
+    221,
 /**/
     220,
 /**/

-- 
-- 
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 visit 
https://groups.google.com/d/msgid/vim_dev/E1w4LDg-000eBc-4P%40256bit.org.

Raspunde prin e-mail lui