diff options
author | zeertzjq <zeertzjq@outlook.com> | 2024-05-23 07:47:55 +0200 |
---|---|---|
committer | Christian Brabandt <cb@256bit.org> | 2024-05-23 07:47:55 +0200 |
commit | 701ad50a9efcf0adfe6d787b606c4e4dbd31f26d (patch) | |
tree | a9f93efb26cf90fe4ea9cbb79d1059d07bd345b2 /src/normal.c | |
parent | f2d74e3b63e8ba4ed620ae41119929b327c7cfbf (diff) |
patch 9.1.0433: Wrong yanking with exclusive selection and ve=allv9.1.0433
Problem: Wrong yanking with exclusive selection and virtualedit=all,
and integer overflow when using getregion() on it.
Solution: Set coladd when decreasing column and 'virtualedit' is active.
Add more tests for getregion() with 'virtualedit' (zeertzjq).
closes: #14830
Signed-off-by: zeertzjq <zeertzjq@outlook.com>
Signed-off-by: Christian Brabandt <cb@256bit.org>
Diffstat (limited to 'src/normal.c')
-rw-r--r-- | src/normal.c | 47 |
1 files changed, 29 insertions, 18 deletions
diff --git a/src/normal.c b/src/normal.c index 38c6bad80f..b55d941fcc 100644 --- a/src/normal.c +++ b/src/normal.c @@ -6696,29 +6696,40 @@ adjust_for_sel(cmdarg_T *cap) int unadjust_for_sel(void) { - pos_T *pp; - if (*p_sel == 'e' && !EQUAL_POS(VIsual, curwin->w_cursor)) + return unadjust_for_sel_inner(LT_POS(VIsual, curwin->w_cursor) + ? &curwin->w_cursor : &VIsual); + return FALSE; +} + +/* + * Move position "*pp" back one character for 'selection' == "exclusive". + * Returns TRUE when backed up to the previous line. + */ + int +unadjust_for_sel_inner(pos_T *pp) +{ + colnr_T cs, ce; + + if (pp->coladd > 0) + --pp->coladd; + else if (pp->col > 0) { - if (LT_POS(VIsual, curwin->w_cursor)) - pp = &curwin->w_cursor; - else - pp = &VIsual; - if (pp->coladd > 0) - --pp->coladd; - else - if (pp->col > 0) - { - --pp->col; - mb_adjustpos(curbuf, pp); - } - else if (pp->lnum > 1) + --pp->col; + mb_adjustpos(curbuf, pp); + if (virtual_active()) { - --pp->lnum; - pp->col = ml_get_len(pp->lnum); - return TRUE; + getvcol(curwin, pp, &cs, NULL, &ce); + pp->coladd = ce - cs; } } + else if (pp->lnum > 1) + { + --pp->lnum; + pp->col = ml_get_len(pp->lnum); + return TRUE; + } + return FALSE; } |