refactor(ops): use op_yank_reg() instead of op_yank() when deleting

Needed for Vim patch 8.1.0999.
This commit is contained in:
zeertzjq
2022-02-23 11:11:23 +08:00
parent 205b3765f2
commit f6d507f5ba
2 changed files with 12 additions and 13 deletions

View File

@@ -8160,7 +8160,7 @@ static void ex_operators(exarg_T *eap)
case CMD_yank: case CMD_yank:
oa.op_type = OP_YANK; oa.op_type = OP_YANK;
(void)op_yank(&oa, true, false); (void)op_yank(&oa, true);
break; break;
default: // CMD_rshift or CMD_lshift default: // CMD_rshift or CMD_lshift

View File

@@ -1572,12 +1572,14 @@ int op_delete(oparg_T *oap)
yankreg_T *reg = NULL; yankreg_T *reg = NULL;
int did_yank = false; int did_yank = false;
if (oap->regname != 0) { if (oap->regname != 0) {
// yank without message // check for read-only register
did_yank = op_yank(oap, false, true); if (!valid_yank_reg(oap->regname, true)) {
if (!did_yank) { beep_flush();
// op_yank failed, don't do anything
return OK; return OK;
} }
reg = get_yank_register(oap->regname, YREG_YANK); // yank into specif'd reg
op_yank_reg(oap, false, reg, is_append_register(oap->regname)); // yank without message
did_yank = true;
} }
/* /*
@@ -2647,12 +2649,12 @@ void free_register(yankreg_T *reg)
/// Yanks the text between "oap->start" and "oap->end" into a yank register. /// Yanks the text between "oap->start" and "oap->end" into a yank register.
/// If we are to append (uppercase register), we first yank into a new yank /// If we are to append (uppercase register), we first yank into a new yank
/// register and then concatenate the old and the new one. /// register and then concatenate the old and the new one.
/// Do not call this from a delete operation. Use op_yank_reg() instead.
/// ///
/// @param oap operator arguments /// @param oap operator arguments
/// @param message show message when more than `&report` lines are yanked. /// @param message show message when more than `&report` lines are yanked.
/// @param deleting whether the function was called from a delete operation.
/// @returns whether the operation register was writable. /// @returns whether the operation register was writable.
bool op_yank(oparg_T *oap, bool message, int deleting) bool op_yank(oparg_T *oap, bool message)
FUNC_ATTR_NONNULL_ALL FUNC_ATTR_NONNULL_ALL
{ {
// check for read-only register // check for read-only register
@@ -2666,11 +2668,8 @@ bool op_yank(oparg_T *oap, bool message, int deleting)
yankreg_T *reg = get_yank_register(oap->regname, YREG_YANK); yankreg_T *reg = get_yank_register(oap->regname, YREG_YANK);
op_yank_reg(oap, message, reg, is_append_register(oap->regname)); op_yank_reg(oap, message, reg, is_append_register(oap->regname));
// op_delete will set_clipboard and do_autocmd set_clipboard(oap->regname, reg);
if (!deleting) { do_autocmd_textyankpost(oap, reg);
set_clipboard(oap->regname, reg);
do_autocmd_textyankpost(oap, reg);
}
return true; return true;
} }
@@ -6698,7 +6697,7 @@ void do_pending_operator(cmdarg_T *cap, int old_col, bool gui_yank)
} else { } else {
curwin->w_p_lbr = lbr_saved; curwin->w_p_lbr = lbr_saved;
oap->excl_tr_ws = cap->cmdchar == 'z'; oap->excl_tr_ws = cap->cmdchar == 'z';
(void)op_yank(oap, !gui_yank, false); (void)op_yank(oap, !gui_yank);
} }
check_cursor_col(); check_cursor_col();
break; break;