patch 9.1.0082: Redrawing can be improved when deleting lines with 'cursorline'

Commit: 
https://github.com/vim/vim/commit/7ce34c9a947b17a8b5e81e7c2335a63552182d10
Author: zeertzjq <zeert...@outlook.com>
Date:   Thu Feb 8 11:34:55 2024 +0100

    patch 9.1.0082: Redrawing can be improved when deleting lines with 
'cursorline'
    
    Problem:  Redrawing can be improved when deleting lines with 'cursorline'.
    Solution: Use smarter invalidation and adjustment.  Remove unnecessary
              UPD_VALID as it is already set at the top of the loop.  Make
              the test for #4862 fail without the fix.
              (zeertzjq)
    
    closes: #13986
    
    Signed-off-by: zeertzjq <zeert...@outlook.com>
    Signed-off-by: Christian Brabandt <c...@256bit.org>

diff --git a/src/change.c b/src/change.c
index c0b8785ba..0ea424f98 100644
--- a/src/change.c
+++ b/src/change.c
@@ -656,22 +656,20 @@ changed_common(
                set_topline(wp, wp->w_topline);
 #endif
            // If lines have been added or removed, relative numbering always
-           // requires a redraw.
+           // requires an update even if cursor didn't move.
            if (wp->w_p_rnu && xtra != 0)
-           {
                wp->w_last_cursor_lnum_rnu = 0;
-               redraw_win_later(wp, UPD_VALID);
-           }
+
 #ifdef FEAT_SYN_HL
-           // Cursor line highlighting probably need to be updated with
-           // "UPD_VALID" if it's below the change.
-           // If the cursor line is inside the change we need to redraw more.
-           if (wp->w_p_cul)
+           if (wp->w_p_cul && wp->w_last_cursorline >= lnum)
            {
-               if (xtra == 0)
-                   redraw_win_later(wp, UPD_VALID);
-               else if (lnum <= wp->w_last_cursorline)
-                   redraw_win_later(wp, UPD_SOME_VALID);
+               if (wp->w_last_cursorline < lnume)
+                   // If 'cursorline' was inside the change, it has already
+                   // been invalidated in w_lines[] by the loop above.
+                   wp->w_last_cursorline = 0;
+               else
+                   // If 'cursorline' was below the change, adjust its lnum.
+                   wp->w_last_cursorline += xtra;
            }
 #endif
        }
diff --git a/src/testdir/test_highlight.vim b/src/testdir/test_highlight.vim
index b831878b4..d6c9f5005 100644
--- a/src/testdir/test_highlight.vim
+++ b/src/testdir/test_highlight.vim
@@ -557,22 +557,23 @@ func Test_cursorline_after_yank()
   call StopVimInTerminal(buf)
 endfunc
 
-" test for issue #4862
+" Test for issue #4862: pasting above 'cursorline' redraws properly.
 func Test_put_before_cursorline()
   new
   only!
-  call setline(1, 'A')
+  call setline(1, ['A', 'B', 'C'])
+  call cursor(2, 1)
   redraw
-  let std_attr = screenattr(1, 1)
+  let std_attr = screenattr(2, 1)
   set cursorline
   redraw
-  let cul_attr = screenattr(1, 1)
+  let cul_attr = screenattr(2, 1)
   normal yyP
   redraw
-  " Line 1 has cursor so it should be highlighted with CursorLine.
-  call assert_equal(cul_attr, screenattr(1, 1))
-  " And CursorLine highlighting from the second line should be gone.
-  call assert_equal(std_attr, screenattr(2, 1))
+  " Line 2 has cursor so it should be highlighted with CursorLine.
+  call assert_equal(cul_attr, screenattr(2, 1))
+  " And CursorLine highlighting from line 3 should be gone.
+  call assert_equal(std_attr, screenattr(3, 1))
   set nocursorline
   bwipe!
 endfunc
diff --git a/src/version.c b/src/version.c
index 408dd37b9..7e07e66f5 100644
--- a/src/version.c
+++ b/src/version.c
@@ -704,6 +704,8 @@ static char *(features[]) =
 
 static int included_patches[] =
 {   /* Add new patch number below this line */
+/**/
+    82,
 /**/
     81,
 /**/

-- 
-- 
You received this message from the "vim_dev" maillist.
Do not top-post! Type your reply below the text you are replying to.
For more information, visit http://www.vim.org/maillist.php

--- 
You received this message because you are subscribed to the Google Groups 
"vim_dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to vim_dev+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/vim_dev/E1rY1tv-002zWC-Ef%40256bit.org.

Reply via email to