]> granicus.if.org Git - vim/commitdiff
patch 8.2.3095: with 'virtualedit' set to "block" block selection is wrong v8.2.3095
authorBram Moolenaar <Bram@vim.org>
Sat, 3 Jul 2021 20:15:17 +0000 (22:15 +0200)
committerBram Moolenaar <Bram@vim.org>
Sat, 3 Jul 2021 20:15:17 +0000 (22:15 +0200)
Problem:    With 'virtualedit' set to "block" block selection is wrong after
            using "$".  (Marco Trosi)
Solution:   Compute the longest selected line. (closes #8495)

src/drawscreen.c
src/testdir/dumps/Test_visual_block_with_virtualedit2.dump [new file with mode: 0644]
src/testdir/test_visual.vim
src/version.c

index 7927bedc23000764893998d4f271d70f39e077ee..5f531f2d00d6f7dce9b9764b27e5c4a94b1bab9a 100644 (file)
@@ -2009,14 +2009,41 @@ win_update(win_T *wp)
                    ve_flags = VE_ALL;
 #endif
                getvcols(wp, &VIsual, &curwin->w_cursor, &fromc, &toc);
+               ++toc;
 #if defined(FEAT_LINEBREAK)
                ve_flags = save_ve_flags;
 #endif
-               ++toc;
                // Highlight to the end of the line, unless 'virtualedit' has
                // "block".
-               if (curwin->w_curswant == MAXCOL && !(ve_flags & VE_BLOCK))
-                   toc = MAXCOL;
+               if (curwin->w_curswant == MAXCOL)
+               {
+                   if (ve_flags & VE_BLOCK)
+                   {
+                       pos_T       pos;
+                       int         cursor_above =
+                                          curwin->w_cursor.lnum < VIsual.lnum;
+
+                       // Need to find the longest line.
+                       toc = 0;
+                       pos.coladd = 0;
+                       for (pos.lnum = curwin->w_cursor.lnum; cursor_above
+                                       ? pos.lnum <= VIsual.lnum
+                                       : pos.lnum >= VIsual.lnum;
+                                            pos.lnum += cursor_above ? 1 : -1)
+                       {
+                           colnr_T t;
+
+                           pos.col = STRLEN(ml_get_buf(wp->w_buffer,
+                                                            pos.lnum, FALSE));
+                           getvvcol(wp, &pos, NULL, NULL, &t);
+                           if (toc < t)
+                               toc = t;
+                       }
+                       ++toc;
+                   }
+                   else
+                       toc = MAXCOL;
+               }
 
                if (fromc != wp->w_old_cursor_fcol
                        || toc != wp->w_old_cursor_lcol)
diff --git a/src/testdir/dumps/Test_visual_block_with_virtualedit2.dump b/src/testdir/dumps/Test_visual_block_with_virtualedit2.dump
new file mode 100644 (file)
index 0000000..3c62156
--- /dev/null
@@ -0,0 +1,8 @@
+|a+0&#e0e0e08@5| | +0&#ffffff0@42
+|b+0&#e0e0e08@3| @2| +0&#ffffff0@42
+|c+0&#e0e0e08@1> +0&#ffffff0| +0&#e0e0e08@3| +0&#ffffff0@42
+|~+0#4040ff13&| @48
+|~| @48
+|~| @48
+|~| @48
+|-+2#0000000&@1| |V|I|S|U|A|L| |B|L|O|C|K| |-@1| +0&&@3|3|x|3| @6|3|,|3| @10|A|l@1| 
index 5b2a32cfee0cd15ac629afc457fb177ad5a6e28b..3df6533d1bef986bc259650c084f18cdd72718a1 100644 (file)
@@ -1256,6 +1256,9 @@ func Test_visual_block_with_virtualedit()
   call term_sendkeys(buf, "\<C-V>gg$")
   call VerifyScreenDump(buf, 'Test_visual_block_with_virtualedit', {})
 
+  call term_sendkeys(buf, "\<Esc>gg\<C-V>G$")
+  call VerifyScreenDump(buf, 'Test_visual_block_with_virtualedit2', {})
+
   " clean up
   call term_sendkeys(buf, "\<Esc>")
   call StopVimInTerminal(buf)
index 79a6a85998129305f4841eb67c9aac1ca3d551b8..e4bb59685e15ea2a4efdeabf70cf3be04f20b7c8 100644 (file)
@@ -755,6 +755,8 @@ static char *(features[]) =
 
 static int included_patches[] =
 {   /* Add new patch number below this line */
+/**/
+    3095,
 /**/
     3094,
 /**/