diff options
author | Bram Moolenaar <Bram@vim.org> | 2022-02-14 14:51:22 +0000 |
---|---|---|
committer | Bram Moolenaar <Bram@vim.org> | 2022-02-14 14:51:22 +0000 |
commit | 55737c2a31ed450dd7bf2a9c587adfbb32b755bb (patch) | |
tree | 7c91d8be0f82729aec1870c0c3ef521ff792b063 | |
parent | 6dd7424c7e6ab81998c29ca3526c41b75cfde5a1 (diff) | |
download | vim-git-55737c2a31ed450dd7bf2a9c587adfbb32b755bb.tar.gz |
patch 8.2.4379: an empty change is reported to a listenerv8.2.4379
Problem: An empty change is reported to a listener.
Solution: Do not report an empty change. (closes #9768) Remove unused
return value.
-rw-r--r-- | src/change.c | 7 | ||||
-rw-r--r-- | src/testdir/test_listener.vim | 31 | ||||
-rw-r--r-- | src/undo.c | 4 | ||||
-rw-r--r-- | src/version.c | 2 |
4 files changed, 37 insertions, 7 deletions
diff --git a/src/change.c b/src/change.c index 25a084190..771f7675b 100644 --- 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 index 343fb98e3..82b5ff03c 100644 --- 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 index 1ed720c5b..1a4f6d064 100644 --- 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 index 4b2ac38bb..22f0a5a53 100644 --- 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, |