diff options
author | zeertzjq <zeertzjq@outlook.com> | 2024-03-07 06:43:08 +0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2024-03-07 06:43:08 +0800 |
commit | 6525832a8c4d44a8ebabba02a5ea1ce09b389a4f (patch) | |
tree | 9edf1b25fcf5b2e953319916f8b605c3af106b53 /src/nvim/eval/funcs.c | |
parent | ae5095cac9b233cfb6785534de6f084c70dc6424 (diff) | |
download | rneovim-6525832a8c4d44a8ebabba02a5ea1ce09b389a4f.tar.gz rneovim-6525832a8c4d44a8ebabba02a5ea1ce09b389a4f.tar.bz2 rneovim-6525832a8c4d44a8ebabba02a5ea1ce09b389a4f.zip |
vim-patch:9.1.0155: can only get getregion() from current buffer (#27757)
Problem: can only call getregion() for current buffer
Solution: Allow to retrieve selections from different buffers
(Shougo Matsushita)
closes: vim/vim#14131
https://github.com/vim/vim/commit/84bf6e658da51126bdd2e50af1f40cabd149343f
Co-authored-by: Shougo Matsushita <Shougo.Matsu@gmail.com>
Diffstat (limited to 'src/nvim/eval/funcs.c')
-rw-r--r-- | src/nvim/eval/funcs.c | 32 |
1 files changed, 22 insertions, 10 deletions
diff --git a/src/nvim/eval/funcs.c b/src/nvim/eval/funcs.c index 605170610c..67443b66bc 100644 --- a/src/nvim/eval/funcs.c +++ b/src/nvim/eval/funcs.c @@ -2827,16 +2827,12 @@ static void f_getregion(typval_T *argvars, typval_T *rettv, EvalFuncData fptr) return; } - int fnum = -1; - pos_T p1; - if (list2fpos(&argvars[0], &p1, &fnum, NULL, false) != OK - || (fnum >= 0 && fnum != curbuf->b_fnum)) { - return; - } - - pos_T p2; - if (list2fpos(&argvars[1], &p2, &fnum, NULL, false) != OK - || (fnum >= 0 && fnum != curbuf->b_fnum)) { + int fnum1 = -1; + int fnum2 = -1; + pos_T p1, p2; + if (list2fpos(&argvars[0], &p1, &fnum1, NULL, false) != OK + || list2fpos(&argvars[1], &p2, &fnum2, NULL, false) != OK + || fnum1 != fnum2) { return; } @@ -2866,6 +2862,18 @@ static void f_getregion(typval_T *argvars, typval_T *rettv, EvalFuncData fptr) return; } + buf_T *save_curbuf = curbuf; + + if (fnum1 != 0) { + buf_T *findbuf = buflist_findnr(fnum1); + // buffer not loaded + if (findbuf == NULL || findbuf->b_ml.ml_mfp == NULL) { + return; + } + save_curbuf = curbuf; + curbuf = findbuf; + } + const TriState save_virtual = virtual_op; virtual_op = virtual_active(); @@ -2948,6 +2956,10 @@ static void f_getregion(typval_T *argvars, typval_T *rettv, EvalFuncData fptr) tv_list_append_allocated_string(rettv->vval.v_list, akt); } + if (curbuf != save_curbuf) { + curbuf = save_curbuf; + } + virtual_op = save_virtual; } |