Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 7cc2b72

Browse filesBrowse files
gelguyjustinmk
authored andcommitted
TextYankPost: spurious/too-early dispatch during delete #10392
Problem: delete-with-register dispatches TextYankPost before updating yank registers Solution: Add flag to op_yank(). Fixes #10225
1 parent 4213492 commit 7cc2b72
Copy full SHA for 7cc2b72

File tree

Expand file treeCollapse file tree

4 files changed

+21
-8
lines changed
Filter options
Expand file treeCollapse file tree

4 files changed

+21
-8
lines changed

‎src/nvim/ex_docmd.c

Copy file name to clipboardExpand all lines: src/nvim/ex_docmd.c
+1-1Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7520,7 +7520,7 @@ static void ex_operators(exarg_T *eap)
75207520

75217521
case CMD_yank:
75227522
oa.op_type = OP_YANK;
7523-
(void)op_yank(&oa, true);
7523+
(void)op_yank(&oa, true, false);
75247524
break;
75257525

75267526
default: /* CMD_rshift or CMD_lshift */

‎src/nvim/normal.c

Copy file name to clipboardExpand all lines: src/nvim/normal.c
+1-1Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1817,7 +1817,7 @@ void do_pending_operator(cmdarg_T *cap, int old_col, bool gui_yank)
18171817
}
18181818
} else {
18191819
curwin->w_p_lbr = lbr_saved;
1820-
(void)op_yank(oap, !gui_yank);
1820+
(void)op_yank(oap, !gui_yank, false);
18211821
}
18221822
check_cursor_col();
18231823
break;

‎src/nvim/ops.c

Copy file name to clipboardExpand all lines: src/nvim/ops.c
+14-6Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1400,9 +1400,11 @@ int op_delete(oparg_T *oap)
14001400
*/
14011401
if (oap->regname != '_') {
14021402
yankreg_T *reg = NULL;
1403+
int did_yank = false;
14031404
if (oap->regname != 0) {
14041405
//yank without message
1405-
if (!op_yank(oap, false)) {
1406+
did_yank = op_yank(oap, false, true);
1407+
if (!did_yank) {
14061408
// op_yank failed, don't do anything
14071409
return OK;
14081410
}
@@ -1423,6 +1425,7 @@ int op_delete(oparg_T *oap)
14231425
y_regs[1].y_array = NULL; // set register "1 to empty
14241426
reg = &y_regs[1];
14251427
op_yank_reg(oap, false, reg, false);
1428+
did_yank = true;
14261429
}
14271430

14281431
/* Yank into small delete register when no named register specified
@@ -1431,13 +1434,14 @@ int op_delete(oparg_T *oap)
14311434
&& oap->line_count == 1) {
14321435
reg = get_yank_register('-', YREG_YANK);
14331436
op_yank_reg(oap, false, reg, false);
1437+
did_yank = true;
14341438
}
14351439

1436-
if (oap->regname == 0) {
1440+
if (did_yank || oap->regname == 0) {
14371441
if (reg == NULL) {
14381442
abort();
14391443
}
1440-
set_clipboard(0, reg);
1444+
set_clipboard(oap->regname, reg);
14411445
do_autocmd_textyankpost(oap, reg);
14421446
}
14431447

@@ -2376,8 +2380,9 @@ void free_register(yankreg_T *reg)
23762380
///
23772381
/// @param oap operator arguments
23782382
/// @param message show message when more than `&report` lines are yanked.
2383+
/// @param deleting whether the function was called from a delete operation.
23792384
/// @returns whether the operation register was writable.
2380-
bool op_yank(oparg_T *oap, bool message)
2385+
bool op_yank(oparg_T *oap, bool message, int deleting)
23812386
FUNC_ATTR_NONNULL_ALL
23822387
{
23832388
// check for read-only register
@@ -2391,8 +2396,11 @@ bool op_yank(oparg_T *oap, bool message)
23912396

23922397
yankreg_T *reg = get_yank_register(oap->regname, YREG_YANK);
23932398
op_yank_reg(oap, message, reg, is_append_register(oap->regname));
2394-
set_clipboard(oap->regname, reg);
2395-
do_autocmd_textyankpost(oap, reg);
2399+
// op_delete will set_clipboard and do_autocmd
2400+
if (!deleting) {
2401+
set_clipboard(oap->regname, reg);
2402+
do_autocmd_textyankpost(oap, reg);
2403+
}
23962404

23972405
return true;
23982406
}

‎test/functional/autocmd/textyankpost_spec.lua

Copy file name to clipboardExpand all lines: test/functional/autocmd/textyankpost_spec.lua
+5Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -229,4 +229,9 @@ describe('TextYankPost', function()
229229
eq(4, eval('g:count'))
230230
end)
231231

232+
it('updates numbered registers correctly #10225', function()
233+
command('autocmd TextYankPost * let g:reg = getreg("1")')
234+
feed('"adj')
235+
eq('foo\nbar\nbaz text\n', eval('g:reg'))
236+
end)
232237
end)

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.