patch 9.1.0729: Wrong cursor-screenline when resizing window

Commit: 
https://github.com/vim/vim/commit/86dc4f8b432233a01d022c3e71df53db58229713
Author: zeertzjq <zeert...@outlook.com>
Date:   Sat Sep 14 10:37:17 2024 +0200

    patch 9.1.0729: Wrong cursor-screenline when resizing window
    
    Problem:  Wrong cursor-screenline when resizing window
    Solution: Invalidate saved left_col and right_col when width1 or width2
              change.
    
    closes: #15679
    
    Signed-off-by: zeertzjq <zeert...@outlook.com>
    Signed-off-by: Christian Brabandt <c...@256bit.org>

diff --git a/src/drawline.c b/src/drawline.c
index e388bdbee..b627192a4 100644
--- a/src/drawline.c
+++ b/src/drawline.c
@@ -39,25 +39,26 @@ margin_columns_win(win_T *wp, int *left_col, int *right_col)
     // cache previous calculations depending on w_virtcol
     static int saved_w_virtcol;
     static win_T *prev_wp;
+    static int prev_width1;
+    static int prev_width2;
     static int prev_left_col;
     static int prev_right_col;
-    static int prev_col_off;
 
     int cur_col_off = win_col_off(wp);
     int        width1;
     int        width2;
 
-    if (saved_w_virtcol == wp->w_virtcol
-           && prev_wp == wp && prev_col_off == cur_col_off)
+    width1 = wp->w_width - cur_col_off;
+    width2 = width1 + win_col_off2(wp);
+
+    if (saved_w_virtcol == wp->w_virtcol && prev_wp == wp
+           && prev_width1 == width1 && prev_width2 == width2)
     {
        *right_col = prev_right_col;
        *left_col = prev_left_col;
        return;
     }
 
-    width1 = wp->w_width - cur_col_off;
-    width2 = width1 + win_col_off2(wp);
-
     *left_col = 0;
     *right_col = width1;
 
@@ -70,8 +71,9 @@ margin_columns_win(win_T *wp, int *left_col, int *right_col)
     prev_left_col = *left_col;
     prev_right_col = *right_col;
     prev_wp = wp;
+    prev_width1 = width1;
+    prev_width2 = width2;
     saved_w_virtcol = wp->w_virtcol;
-    prev_col_off = cur_col_off;
 }
 #endif
 
diff --git a/src/testdir/dumps/Test_cursorline_screenline_resize_1.dump 
b/src/testdir/dumps/Test_cursorline_screenline_resize_1.dump
new file mode 100644
index 000000000..dd5636277
--- /dev/null
+++ b/src/testdir/dumps/Test_cursorline_screenline_resize_1.dump
@@ -0,0 +1,8 @@
+| +0#af5f00255#ffffff0@1|1| |x+0#0000000&|y|z| |x|y|z| |x|y|z| |x|y|z| |x|y|z| 
|x|y|z| |x|y|z| |x|y|z| |x|y|z| |x|y|z| |x|y|z| |x|y||+1&&| +0&&@23
+| +0#af5f00255&@3|z+0#0000000&| |x|y|z| |x|y|z| |x|y|z| |x|y|z| |x|y|z| 
|x|y|z| |x|y|z| |x|y|z| |x|y|z| |x|y|z| |x|y|z| ||+1&&|~+0#4040ff13&| @22
+| +0#af5f00255&@3|x+8#0000000&|y|z| |x|y|z| |x|y|z| |x|y|z| |x|y|z| |x|y|z| 
|x|y|z> @18||+1&&|~+0#4040ff13&| @22
+|~| @48||+1#0000000&|~+0#4040ff13&| @22
+|~| @48||+1#0000000&|~+0#4040ff13&| @22
+|~| @48||+1#0000000&|~+0#4040ff13&| @22
+|[+3#0000000&|N|o| |N|a|m|e|]| |[|+|]| @18|1|,|1|2|0| @9|A|l@1| |[+1&&|N|o| 
|N|a|m|e|]| @2|0|,|0|-|1| @3|A|l@1
+| +0&&@74
diff --git a/src/testdir/dumps/Test_cursorline_screenline_resize_2.dump 
b/src/testdir/dumps/Test_cursorline_screenline_resize_2.dump
new file mode 100644
index 000000000..466bea3f4
--- /dev/null
+++ b/src/testdir/dumps/Test_cursorline_screenline_resize_2.dump
@@ -0,0 +1,8 @@
+| +0#af5f00255#ffffff0@1|1| |x+0#0000000&|y|z| |x|y|z| |x|y|z| |x|y|z| |x|y|z| 
|x|y|z| |x|y|z| |x|y|z| |x|y|z| |x|y|z| |x|y||+1&&| +0&&@27
+| +0#af5f00255&@3|z+0#0000000&| |x|y|z| |x|y|z| |x|y|z| |x|y|z| |x|y|z| 
|x|y|z| |x|y|z| |x|y|z| |x|y|z| |x|y|z| ||+1&&|~+0#4040ff13&| @26
+| +0#af5f00255&@3|x+8#0000000&|y|z| |x|y|z| |x|y|z| |x|y|z| |x|y|z| |x|y|z| 
|x|y|z| |x|y|z| |x|y|z> @6||+1&&|~+0#4040ff13&| @26
+|~| @44||+1#0000000&|~+0#4040ff13&| @26
+|~| @44||+1#0000000&|~+0#4040ff13&| @26
+|~| @44||+1#0000000&|~+0#4040ff13&| @26
+|[+3#0000000&|N|o| |N|a|m|e|]| |[|+|]| @14|1|,|1|2|0| @9|A|l@1| |[+1&&|N|o| 
|N|a|m|e|]| @4|0|,|0|-|1| @5|A|l@1
+|:+0&&|v|e|r|t|i|c|a|l| |r|e|s|i|z|e| |-|4| @55
diff --git a/src/testdir/dumps/Test_cursorline_screenline_resize_3.dump 
b/src/testdir/dumps/Test_cursorline_screenline_resize_3.dump
new file mode 100644
index 000000000..47152b63b
--- /dev/null
+++ b/src/testdir/dumps/Test_cursorline_screenline_resize_3.dump
@@ -0,0 +1,8 @@
+| +0#af5f00255#ffffff0@1|1| |x+0#0000000&|y|z| |x|y|z| |x|y|z| |x|y|z| |x|y|z| 
|x|y|z| |x|y|z| |x|y|z| |x|y|z| |x|y|z| |x|y||+1&&| +0&&@27
+|z| |x|y|z| |x|y|z| |x|y|z| |x|y|z| |x|y|z| |x|y|z| |x|y|z| |x|y|z| |x|y|z| 
|x|y|z| |x|y|z| ||+1&&|~+0#4040ff13&| @26
+|x+8#0000000&|y|z| |x|y|z| |x|y|z| |x|y|z| |x|y|z| |x|y|z| |x|y|z| |x|y|z> 
@14||+1&&|~+0#4040ff13&| @26
+|~| @44||+1#0000000&|~+0#4040ff13&| @26
+|~| @44||+1#0000000&|~+0#4040ff13&| @26
+|~| @44||+1#0000000&|~+0#4040ff13&| @26
+|[+3#0000000&|N|o| |N|a|m|e|]| |[|+|]| @14|1|,|1|2|0| @9|A|l@1| |[+1&&|N|o| 
|N|a|m|e|]| @4|0|,|0|-|1| @5|A|l@1
+|:+0&&|s|e|t| |c|p|o|p|t|i|o|n|s|+|=|n| @57
diff --git a/src/testdir/test_cursorline.vim b/src/testdir/test_cursorline.vim
index f4c58dec1..bdde670d2 100644
--- a/src/testdir/test_cursorline.vim
+++ b/src/testdir/test_cursorline.vim
@@ -268,6 +268,27 @@ func Test_cursorline_callback()
   call StopVimInTerminal(buf)
 endfunc
 
+func Test_cursorline_screenline_resize()
+  CheckScreendump
+
+  let lines =<< trim END
+      50vnew
+      call setline(1, repeat('xyz ', 30))
+      setlocal number cursorline cursorlineopt=screenline
+      normal! $
+  END
+  call writefile(lines, 'Xcul_screenline_resize', 'D')
+
+  let buf = RunVimInTerminal('-S Xcul_screenline_resize', #{rows: 8})
+  call VerifyScreenDump(buf, 'Test_cursorline_screenline_resize_1', {})
+  call term_sendkeys(buf, ":vertical resize -4\<CR>")
+  call VerifyScreenDump(buf, 'Test_cursorline_screenline_resize_2', {})
+  call term_sendkeys(buf, ":set cpoptions+=n\<CR>")
+  call VerifyScreenDump(buf, 'Test_cursorline_screenline_resize_3', {})
+
+  call StopVimInTerminal(buf)
+endfunc
+
 func Test_cursorline_screenline_update()
   CheckScreendump
 
diff --git a/src/version.c b/src/version.c
index ba33f431d..c1ee2d575 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 */
+/**/
+    729,
 /**/
     728,
 /**/

-- 
-- 
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/E1spOOy-00FiHy-5F%40256bit.org.

Raspunde prin e-mail lui