]> granicus.if.org Git - vim/commitdiff
patch 8.1.2211: listener callback "added" argument is not the total v8.1.2211
authorBram Moolenaar <Bram@vim.org>
Thu, 24 Oct 2019 18:07:07 +0000 (20:07 +0200)
committerBram Moolenaar <Bram@vim.org>
Thu, 24 Oct 2019 18:07:07 +0000 (20:07 +0200)
Problem:    Listener callback "added" argument is not the total. (Andy
            Massimino)
Solution:   Compute the total. (closes #5105)

src/change.c
src/testdir/test_listener.vim
src/version.c

index caf9db0d7195cd22f1c2591c57fa7e5dfebf3518..da6a72b569dfa65d537c78b61ac81d80c72af67d 100644 (file)
@@ -371,9 +371,9 @@ invoke_listeners(buf_T *buf)
        if (start > lnum)
            start = lnum;
        lnum = dict_get_number(li->li_tv.vval.v_dict, (char_u *)"end");
-       if (lnum > end)
+       if (end < lnum)
            end = lnum;
-       added = dict_get_number(li->li_tv.vval.v_dict, (char_u *)"added");
+       added += dict_get_number(li->li_tv.vval.v_dict, (char_u *)"added");
     }
     argv[1].v_type = VAR_NUMBER;
     argv[1].vval.v_number = start;
index 8c265be2db9f6d48853b7b0ad650b161b5f4865a..a7815dc046d41c6975a7b813f47e266ef2978bb5 100644 (file)
@@ -1,7 +1,9 @@
 " tests for listener_add() and listener_remove()
 
-func s:StoreList(s, l)
+func s:StoreList(s, e, a, l)
   let s:start = a:s
+  let s:end = a:e
+  let s:added = a:a
   let s:text = getline(a:s)
   let s:list = a:l
 endfunc
@@ -19,7 +21,7 @@ func Test_listening()
   new
   call setline(1, ['one', 'two'])
   let s:list = []
-  let id = listener_add({b, s, e, a, l -> s:StoreList(s, l)})
+  let id = listener_add({b, s, e, a, l -> s:StoreList(s, e, a, l)})
   call setline(1, 'one one')
   call listener_flush()
   call assert_equal([{'lnum': 1, 'end': 2, 'col': 1, 'added': 0}], s:list)
@@ -65,6 +67,9 @@ func Test_listening()
   call bufnr()->listener_flush()
   call assert_equal([{'lnum': 3, 'end': 3, 'col': 1, 'added': 1},
        \ {'lnum': 1, 'end': 2, 'col': 1, 'added': 0}], s:list)
+  call assert_equal(1, s:start)
+  call assert_equal(3, s:end)
+  call assert_equal(1, s:added)
 
   " an insert just above a previous change that was the last one does not get
   " merged
index 0347a68b4dc538e878427491980afb9f2bdb9c56..45c7bc07a11a3aae92f6aa42bfe9f76832daf629 100644 (file)
@@ -741,6 +741,8 @@ static char *(features[]) =
 
 static int included_patches[] =
 {   /* Add new patch number below this line */
+/**/
+    2211,
 /**/
     2210,
 /**/