summaryrefslogtreecommitdiffstats
path: root/src/drawscreen.c
diff options
context:
space:
mode:
authorBram Moolenaar <Bram@vim.org>2021-07-03 22:15:17 +0200
committerBram Moolenaar <Bram@vim.org>2021-07-03 22:15:17 +0200
commitb17ab86e7b8712206aa9ea7198c28db969e25936 (patch)
tree7183ba150e3bd13a42e37be7c452f37ce4fff9e0 /src/drawscreen.c
parentc60e959cba03fae9cff9b2674fab646cc70819fc (diff)
patch 8.2.3095: with 'virtualedit' set to "block" block selection is wrongv8.2.3095
Problem: With 'virtualedit' set to "block" block selection is wrong after using "$". (Marco Trosi) Solution: Compute the longest selected line. (closes #8495)
Diffstat (limited to 'src/drawscreen.c')
-rw-r--r--src/drawscreen.c33
1 files changed, 30 insertions, 3 deletions
diff --git a/src/drawscreen.c b/src/drawscreen.c
index 7927bedc23..5f531f2d00 100644
--- a/src/drawscreen.c
+++ b/src/drawscreen.c
@@ -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)