Merge pull request #17346 from zeertzjq/vim-8.2.4242

vim-patch:8.2.{4242,4315}: put in Visual mode cannot be repeated
This commit is contained in:
zeertzjq
2022-02-09 20:46:30 +08:00
committed by GitHub
7 changed files with 98 additions and 12 deletions

View File

@@ -7509,9 +7509,9 @@ static void nv_put_opt(cmdarg_T *cap, bool fix_indent)
// overwrites if the old contents is being put.
was_visual = true;
regname = cap->oap->regname;
bool save_unnamed = cap->cmdchar == 'P';
// '+' and '*' could be the same selection
bool clipoverwrite = (regname == '+' || regname == '*')
&& (cb_flags & CB_UNNAMEDMASK);
bool clipoverwrite = (regname == '+' || regname == '*') && (cb_flags & CB_UNNAMEDMASK);
if (regname == 0 || regname == '"' || clipoverwrite
|| ascii_isdigit(regname) || regname == '-') {
// The delete might overwrite the register we want to put, save it first
@@ -7524,6 +7524,10 @@ static void nv_put_opt(cmdarg_T *cap, bool fix_indent)
// do_put(), which requires the visual selection to still be active.
if (!VIsual_active || VIsual_mode == 'V' || regname != '.') {
// Now delete the selected text. Avoid messages here.
yankreg_T *old_y_previous;
if (save_unnamed) {
old_y_previous = get_y_previous();
}
cap->cmdchar = 'd';
cap->nchar = NUL;
cap->oap->regname = NUL;
@@ -7533,6 +7537,10 @@ static void nv_put_opt(cmdarg_T *cap, bool fix_indent)
empty = (curbuf->b_ml.ml_flags & ML_EMPTY);
msg_silent--;
if (save_unnamed) {
set_y_previous(old_y_previous);
}
// delete PUT_LINE_BACKWARD;
cap->oap->regname = regname;
}

View File

@@ -135,10 +135,18 @@ static char opchars[][3] =
{ Ctrl_X, NUL, OPF_CHANGE }, // OP_NR_SUB
};
/*
* Translate a command name into an operator type.
* Must only be called with a valid operator name!
*/
yankreg_T *get_y_previous(void)
{
return y_previous;
}
void set_y_previous(yankreg_T *yreg)
{
y_previous = yreg;
}
/// Translate a command name into an operator type.
/// Must only be called with a valid operator name!
int get_op_type(int char1, int char2)
{
int i;

View File

@@ -1184,8 +1184,66 @@ func Test_visual_undo_deletes_last_line()
exe "normal ggvjfxO"
undo
normal gNU
bwipe!
endfunc
func Test_visual_paste()
new
" v_p overwrites unnamed register.
call setline(1, ['xxxx'])
call setreg('"', 'foo')
call setreg('-', 'bar')
normal gg0vp
call assert_equal('x', @")
call assert_equal('x', @-)
call assert_equal('fooxxx', getline(1))
normal $vp
call assert_equal('x', @")
call assert_equal('x', @-)
call assert_equal('fooxxx', getline(1))
" Test with a different register as unnamed register.
call setline(2, ['baz'])
normal 2gg0"rD
call assert_equal('baz', @")
normal gg0vp
call assert_equal('f', @")
call assert_equal('f', @-)
call assert_equal('bazooxxx', getline(1))
normal $vp
call assert_equal('x', @")
call assert_equal('x', @-)
call assert_equal('bazooxxf', getline(1))
if has('clipboard')
" v_P does not overwrite unnamed register.
call setline(1, ['xxxx'])
call setreg('"', 'foo')
call setreg('-', 'bar')
normal gg0vP
call assert_equal('foo', @")
call assert_equal('x', @-)
call assert_equal('fooxxx', getline(1))
normal $vP
call assert_equal('foo', @")
call assert_equal('x', @-)
call assert_equal('fooxxfoo', getline(1))
" Test with a different register as unnamed register.
call setline(2, ['baz'])
normal 2gg0"rD
call assert_equal('baz', @")
normal gg0vP
call assert_equal('baz', @")
call assert_equal('f', @-)
call assert_equal('bazooxxfoo', getline(1))
normal $vP
call assert_equal('baz', @")
call assert_equal('o', @-)
call assert_equal('bazooxxfobaz', getline(1))
endif
bwipe!
endfunc
" vim: shiftwidth=2 sts=2 expandtab