Skip to content

Commit c13fa6a

Browse files
zeertzjqlvimuser
authored andcommitted
fix!: make :undo! notify buffer update callbacks (neovim#20344)
When :undo! was introduced to Nvim the implementation of 'inccommand' preview callback hasn't been fully decided yet, so not notifying buffer update callbacks made sense for 'inccommand' preview callback in case it needs to undo the changes itself. Now it turns out that the undo-and-forget is done automatically for 'inccommand', so it doesn't make sense for :undo! to avoid notifying buffer update callbacks anymore.
1 parent efd5a10 commit c13fa6a

File tree

4 files changed

+25
-7
lines changed

4 files changed

+25
-7
lines changed

src/nvim/ex_docmd.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5867,7 +5867,7 @@ static void ex_undo(exarg_T *eap)
58675867
{
58685868
if (eap->addr_count != 1) {
58695869
if (eap->forceit) {
5870-
u_undo_and_forget(1); // :undo!
5870+
u_undo_and_forget(1, true); // :undo!
58715871
} else {
58725872
u_undo(1); // :undo
58735873
}
@@ -5894,7 +5894,7 @@ static void ex_undo(exarg_T *eap)
58945894
emsg(_(e_undobang_cannot_redo_or_move_branch));
58955895
return;
58965896
}
5897-
u_undo_and_forget(count);
5897+
u_undo_and_forget(count, true);
58985898
} else { // :undo 123
58995899
undo_time(step, false, false, true);
59005900
}

src/nvim/ex_getln.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2194,7 +2194,7 @@ static void cmdpreview_restore_state(CpInfo *cpinfo)
21942194
aco_save_T aco;
21952195
aucmd_prepbuf(&aco, buf);
21962196
// Undo invisibly. This also moves the cursor!
2197-
if (!u_undo_and_forget(count)) {
2197+
if (!u_undo_and_forget(count, false)) {
21982198
abort();
21992199
}
22002200
aucmd_restbuf(&aco);

src/nvim/undo.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1771,16 +1771,16 @@ void u_redo(int count)
17711771

17721772
/// Undo and remove the branch from the undo tree.
17731773
/// Also moves the cursor (as a "normal" undo would).
1774-
bool u_undo_and_forget(int count)
1774+
///
1775+
/// @param do_buf_event If `true`, send the changedtick with the buffer updates
1776+
bool u_undo_and_forget(int count, bool do_buf_event)
17751777
{
17761778
if (curbuf->b_u_synced == false) {
17771779
u_sync(true);
17781780
count = 1;
17791781
}
17801782
undo_undoes = true;
1781-
u_doit(count, true,
1782-
// Don't send nvim_buf_lines_event for u_undo_and_forget().
1783-
false);
1783+
u_doit(count, true, do_buf_event);
17841784

17851785
if (curbuf->b_u_curhead == NULL) {
17861786
// nothing was undone.

test/functional/lua/buffer_updates_spec.lua

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -118,6 +118,24 @@ describe('lua buffer event callbacks: on_lines', function()
118118
}
119119
tick = tick + 1
120120

121+
tick = tick + 1
122+
command('redo')
123+
check_events {
124+
{ "test1", "lines", 1, tick, 3, 5, 4, 32 };
125+
{ "test2", "lines", 1, tick, 3, 5, 4, 32 };
126+
{ "test2", "changedtick", 1, tick+1 };
127+
}
128+
tick = tick + 1
129+
130+
tick = tick + 1
131+
command('undo!')
132+
check_events {
133+
{ "test1", "lines", 1, tick, 3, 4, 5, 13 };
134+
{ "test2", "lines", 1, tick, 3, 4, 5, 13 };
135+
{ "test2", "changedtick", 1, tick+1 };
136+
}
137+
tick = tick + 1
138+
121139
-- simulate next callback returning true
122140
exec_lua("test_unreg = 'test1'")
123141

0 commit comments

Comments
 (0)