# HG changeset patch # User Bram Moolenaar # Date 1644850803 -3600 # Node ID 17cd22b7151b62a36becb18f638db7d8c2f56235 # Parent 327558d9a3313d79d0df9f5cba1e13aa8a7e8314 patch 8.2.4379: an empty change is reported to a listener Commit: https://github.com/vim/vim/commit/55737c2a31ed450dd7bf2a9c587adfbb32b755bb Author: Bram Moolenaar Date: Mon Feb 14 14:51:22 2022 +0000 patch 8.2.4379: an empty change is reported to a listener Problem: An empty change is reported to a listener. Solution: Do not report an empty change. (closes https://github.com/vim/vim/issues/9768) Remove unused return value. diff --git a/src/change.c b/src/change.c --- a/src/change.c +++ b/src/change.c @@ -155,9 +155,8 @@ static long next_listener_id = 0; /* * Check if the change at "lnum" is above or overlaps with an existing * change. If above then flush changes and invoke listeners. - * Returns TRUE if the change was merged. */ - static int + static void check_recorded_changes( buf_T *buf, linenr_T lnum, @@ -185,7 +184,6 @@ check_recorded_changes( } } } - return FALSE; } /* @@ -206,8 +204,7 @@ may_record_change( // If the new change is going to change the line numbers in already listed // changes, then flush. - if (check_recorded_changes(curbuf, lnum, lnume, xtra)) - return; + check_recorded_changes(curbuf, lnum, lnume, xtra); if (curbuf->b_recorded_changes == NULL) { diff --git a/src/testdir/test_listener.vim b/src/testdir/test_listener.vim --- a/src/testdir/test_listener.vim +++ b/src/testdir/test_listener.vim @@ -387,5 +387,36 @@ func Test_remove_listener_in_callback() unlet g:listener_called endfunc +func Test_no_change_for_empty_undo() + new + let text = ['some word here', 'second line'] + call setline(1, text) + let g:entries = [] + func Listener(bufnr, start, end, added, changes) + for change in a:changes + call add(g:entries, [change.lnum, change.end, change.added]) + endfor + endfunc + let s:ID = listener_add('Listener') + let @a = "one line\ntwo line\nthree line" + set undolevels& " start new undo block + call feedkeys('fwviw"ap', 'xt') + call listener_flush(bufnr()) + " first change deletes "word", second change inserts the register + call assert_equal([[1, 2, 0], [1, 2, 2]], g:entries) + let g:entries = [] + + set undolevels& " start new undo block + undo + call listener_flush(bufnr()) + call assert_equal([[1, 4, -2]], g:entries) + call assert_equal(text, getline(1, 2)) + + call listener_remove(s:ID) + bwipe! + unlet g:entries + delfunc Listener +endfunc + " vim: shiftwidth=2 sts=2 expandtab diff --git a/src/undo.c b/src/undo.c --- a/src/undo.c +++ b/src/undo.c @@ -2828,8 +2828,8 @@ u_undoredo(int undo) if (curbuf->b_op_end.lnum > top + oldsize) curbuf->b_op_end.lnum += newsize - oldsize; } - - changed_lines(top + 1, 0, bot, newsize - oldsize); + if (oldsize > 0 || newsize > 0) + changed_lines(top + 1, 0, bot, newsize - oldsize); // set '[ and '] mark if (top + 1 < curbuf->b_op_start.lnum) diff --git a/src/version.c b/src/version.c --- a/src/version.c +++ b/src/version.c @@ -751,6 +751,8 @@ static char *(features[]) = static int included_patches[] = { /* Add new patch number below this line */ /**/ + 4379, +/**/ 4378, /**/ 4377,