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 #9768) Remove unused
return value.
diff --git a/src/change.c b/src/change.c
index 25a0841..771f767 100644
--- a/src/change.c
+++ b/src/change.c
@@ -155,9 +155,8 @@
/*
* 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 @@
}
}
}
- return FALSE;
}
/*
@@ -206,8 +204,7 @@
// 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 343fb98..82b5ff0 100644
--- a/src/testdir/test_listener.vim
+++ b/src/testdir/test_listener.vim
@@ -387,5 +387,36 @@
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 1ed720c..1a4f6d0 100644
--- a/src/undo.c
+++ b/src/undo.c
@@ -2828,8 +2828,8 @@
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 4b2ac38..22f0a5a 100644
--- a/src/version.c
+++ b/src/version.c
@@ -751,6 +751,8 @@
static int included_patches[] =
{ /* Add new patch number below this line */
/**/
+ 4379,
+/**/
4378,
/**/
4377,