1
0
forked from aniani/vim

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.
This commit is contained in:
Bram Moolenaar 2022-02-14 14:51:22 +00:00
parent 6dd7424c7e
commit 55737c2a31
4 changed files with 37 additions and 7 deletions

View File

@ -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)
{

View File

@ -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

View File

@ -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)

View File

@ -750,6 +750,8 @@ static char *(features[]) =
static int included_patches[] =
{ /* Add new patch number below this line */
/**/
4379,
/**/
4378,
/**/