vim-patch:9.1.0166: Internal error with blockwise getregion() in another buffer (#27819)

Problem:  Internal error with blockwise getregion() in another buffer
Solution: Also change curwin->w_buffer when changing curbuf (zeertzjq)

closes: vim/vim#14179

5406eb8722
This commit is contained in:
zeertzjq 2024-03-12 07:19:30 +08:00 committed by GitHub
parent cf156377e8
commit 6481da3015
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 12 additions and 18 deletions

View File

@ -2863,16 +2863,10 @@ static void f_getregion(typval_T *argvars, typval_T *rettv, EvalFuncData fptr)
return; return;
} }
buf_T *const save_curbuf = curbuf; buf_T *findbuf = fnum1 != 0 ? buflist_findnr(fnum1) : curbuf;
buf_T *findbuf = curbuf; if (findbuf == NULL || findbuf->b_ml.ml_mfp == NULL) {
emsg(_(e_buffer_is_not_loaded));
if (fnum1 != 0) { return;
findbuf = buflist_findnr(fnum1);
// buffer not loaded
if (findbuf == NULL || findbuf->b_ml.ml_mfp == NULL) {
emsg(_(e_buffer_is_not_loaded));
return;
}
} }
if (p1.lnum < 1 || p1.lnum > findbuf->b_ml.ml_line_count) { if (p1.lnum < 1 || p1.lnum > findbuf->b_ml.ml_line_count) {
@ -2892,7 +2886,9 @@ static void f_getregion(typval_T *argvars, typval_T *rettv, EvalFuncData fptr)
return; return;
} }
buf_T *const save_curbuf = curbuf;
curbuf = findbuf; curbuf = findbuf;
curwin->w_buffer = curbuf;
const TriState save_virtual = virtual_op; const TriState save_virtual = virtual_op;
virtual_op = virtual_active(); virtual_op = virtual_active();
@ -2975,10 +2971,8 @@ static void f_getregion(typval_T *argvars, typval_T *rettv, EvalFuncData fptr)
tv_list_append_allocated_string(rettv->vval.v_list, akt); tv_list_append_allocated_string(rettv->vval.v_list, akt);
} }
if (curbuf != save_curbuf) { curbuf = save_curbuf;
curbuf = save_curbuf; curwin->w_buffer = curbuf;
}
virtual_op = save_virtual; virtual_op = save_virtual;
} }

View File

@ -1772,11 +1772,11 @@ func Test_visual_getregion()
for type in ['v', 'V', "\<C-V>"] for type in ['v', 'V', "\<C-V>"]
for exclusive in [v:false, v:true] for exclusive in [v:false, v:true]
call assert_equal(range(10)->mapnew('string(v:val)'), call assert_equal(range(10)->mapnew('string(v:val)'),
\ getregion([g:buf, 1, 1, 0], [g:buf, 10, 2, 0]), \ getregion([g:buf, 1, 1, 0], [g:buf, 10, 2, 0],
\ {'type': type, 'exclusive': exclusive }) \ {'type': type, 'exclusive': exclusive }))
call assert_equal(range(10)->mapnew('string(v:val)'), call assert_equal(range(10)->mapnew('string(v:val)'),
\ getregion([g:buf, 10, 2, 0], [g:buf, 1, 1, 0]), \ getregion([g:buf, 10, 2, 0], [g:buf, 1, 1, 0],
\ {'type': type, 'exclusive': exclusive }) \ {'type': type, 'exclusive': exclusive }))
endfor endfor
endfor endfor