]> granicus.if.org Git - vim/commitdiff
patch 8.2.4997: Python: changing hidden buffer can cause display mess up v8.2.4997
authorBram Moolenaar <Bram@vim.org>
Sun, 22 May 2022 11:23:48 +0000 (12:23 +0100)
committerBram Moolenaar <Bram@vim.org>
Sun, 22 May 2022 11:23:48 +0000 (12:23 +0100)
Problem:    Python: changing hidden buffer can cause the display to be messed
            up.
Solution:   Do not mark changed lines when using another buffer. (Paul Ollis,
            closes #10437, closes #7972)

src/if_py_both.h
src/testdir/test_python3.vim
src/version.c

index 0d0a5cef29716288911e32846ee32f871b548ddf..240cc966ae629f819576e9e84c6a9a1c017e8a50 100644 (file)
@@ -4676,9 +4676,11 @@ SetBufferLineList(
        // Only adjust marks if we managed to switch to a window that holds
        // the buffer, otherwise line numbers will be invalid.
        if (save_curbuf.br_buf == NULL)
+       {
            mark_adjust((linenr_T)lo, (linenr_T)(hi - 1),
                                                  (long)MAXLNUM, (long)extra);
-       changed_lines((linenr_T)lo, 0, (linenr_T)hi, (long)extra);
+           changed_lines((linenr_T)lo, 0, (linenr_T)hi, (long)extra);
+       }
 
        if (buf == curbuf && (switchwin.sw_curwin != NULL
                                           || save_curbuf.br_buf == NULL))
index 95d49db2d385a30b71c3a70aa9762a4e2af00488..dd2da400bdf23ca34ef35e24a3419929c0d17358 100644 (file)
@@ -4061,4 +4061,40 @@ func Test_python3_fold_hidden_buffer()
   bwipe! Xa.txt
 endfunc
 
+" Test to catch regression fix #10437.
+func Test_python3_hidden_buf_mod_does_not_mess_up_display()
+  CheckRunVimInTerminal
+
+  let testfile = 'Xtest.vim'
+  let lines =<< trim END
+        set hidden number
+        new
+        hide
+        sil call setline(1, repeat(['aaa'], &lines) + ['bbbbbb'])
+        fu Func()
+        python3 << EOF
+        import vim
+        b = vim.buffers[2]
+        b[:] = ['', '']
+        EOF
+        endfu
+        norm! Gzb
+        call feedkeys(":call Func()\r", 'n')
+  END
+  call writefile(lines, testfile)
+
+  let rows = 10
+  let bufnr = term_start([GetVimProg(), '--clean', '-S', testfile], {'term_rows': rows})
+  call TermWait(bufnr, 100)
+  call assert_equal('run', job_status(term_getjob(bufnr)))
+  let g:test_is_flaky = 0
+  call WaitForAssert({-> assert_match('^  3 aaa$', term_getline(bufnr, 1))})
+  call WaitForAssert({-> assert_match('^ 11 bbbbbb$', term_getline(bufnr, rows - 1))})
+
+  call term_sendkeys(bufnr, ":qall!\<CR>")
+  call WaitForAssert({-> assert_equal('dead', job_status(term_getjob(bufnr)))})
+  exe bufnr . 'bwipe!'
+  call delete(testfile)
+endfunc
+
 " vim: shiftwidth=2 sts=2 expandtab
index fdbb994a4f31117cdfce018a04922ac5f0eba954..5ae7693c5ae21c1ebc084d52bdc3a14aa9790519 100644 (file)
@@ -734,6 +734,8 @@ static char *(features[]) =
 
 static int included_patches[] =
 {   /* Add new patch number below this line */
+/**/
+    4997,
 /**/
     4996,
 /**/