diff options
| author | zeertzjq <zeertzjq@outlook.com> | 2024-05-23 14:23:09 +0800 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2024-05-23 14:23:09 +0800 |
| commit | bdf15dbe6909b39e5d3cf22ae844ebd37862a1a8 (patch) | |
| tree | 4b885d031e34866f6f401683b33d9e04241e0d56 /src/nvim/normal.c | |
| parent | cd48b72b60af0a8b5a7770ab599e4062e974183d (diff) | |
| download | rneovim-bdf15dbe6909b39e5d3cf22ae844ebd37862a1a8.tar.gz rneovim-bdf15dbe6909b39e5d3cf22ae844ebd37862a1a8.tar.bz2 rneovim-bdf15dbe6909b39e5d3cf22ae844ebd37862a1a8.zip | |
vim-patch:9.1.0433: Wrong yanking with exclusive selection and ve=all (#28933)
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: vim/vim#14830
https://github.com/vim/vim/commit/701ad50a9efcf0adfe6d787b606c4e4dbd31f26d
Diffstat (limited to 'src/nvim/normal.c')
| -rw-r--r-- | src/nvim/normal.c | 41 |
1 files changed, 26 insertions, 15 deletions
diff --git a/src/nvim/normal.c b/src/nvim/normal.c index 3b1f0bf73c..8ba375f29d 100644 --- a/src/nvim/normal.c +++ b/src/nvim/normal.c @@ -6014,23 +6014,34 @@ static void adjust_for_sel(cmdarg_T *cap) bool unadjust_for_sel(void) { if (*p_sel == 'e' && !equalpos(VIsual, curwin->w_cursor)) { - pos_T *pp; - if (lt(VIsual, curwin->w_cursor)) { - pp = &curwin->w_cursor; - } else { - pp = &VIsual; - } - if (pp->coladd > 0) { - pp->coladd--; - } else if (pp->col > 0) { - pp->col--; - mark_mb_adjustpos(curbuf, pp); - } else if (pp->lnum > 1) { - pp->lnum--; - pp->col = ml_get_len(pp->lnum); - return true; + return unadjust_for_sel_inner(lt(VIsual, curwin->w_cursor) + ? &curwin->w_cursor : &VIsual); + } + return false; +} + +/// Move position "*pp" back one character for 'selection' == "exclusive". +/// +/// @return true when backed up to the previous line. +bool unadjust_for_sel_inner(pos_T *pp) +{ + colnr_T cs, ce; + + if (pp->coladd > 0) { + pp->coladd--; + } else if (pp->col > 0) { + pp->col--; + mark_mb_adjustpos(curbuf, pp); + if (virtual_active(curwin)) { + 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; } |