patch 9.1.0414: Unable to leave long line with 'smoothscroll' and 'scrolloff'

Commit: 
https://github.com/vim/vim/commit/b32055e504ebd4f6183a93b92b08d61dad61c841
Author: Luuk van Baal <luukvb...@gmail.com>
Date:   Thu May 16 20:44:09 2024 +0200

    patch 9.1.0414: Unable to leave long line with 'smoothscroll' and 
'scrolloff'
    
    Problem:  Unable to leave long line with 'smoothscroll' and 'scrolloff'.
              Corrupted screen near the end of a long line with 'scrolloff'.
              (Ernie Rael, after 9.1.0280)
    Solution: Only correct cursor in case scroll_cursor_bot() was not itself
              called to make the cursor visible. Avoid adjusting for
              'scrolloff' beyond the text line height (Luuk van Baal)
    
    fixes: #14726
    closes: #14783
    
    Signed-off-by: Luuk van Baal <luukvb...@gmail.com>
    Signed-off-by: Christian Brabandt <c...@256bit.org>

diff --git a/src/move.c b/src/move.c
index dd232686e..71654dd76 100644
--- a/src/move.c
+++ b/src/move.c
@@ -2027,6 +2027,8 @@ adjust_skipcol(void)
     long    so = get_scrolloff_value();
     int            scrolloff_cols = so == 0 ? 0 : width1 + (so - 1) * width2;
     int            scrolled = FALSE;
+    int            row = 0;
+    int            overlap, col;
 
     validate_cheight();
     if (curwin->w_cline_height == curwin->w_height
@@ -2041,7 +2043,7 @@ adjust_skipcol(void)
     }
 
     validate_virtcol();
-    int overlap = sms_marker_overlap(curwin, -1);
+    overlap = sms_marker_overlap(curwin, -1);
     while (curwin->w_skipcol > 0
            && curwin->w_virtcol < curwin->w_skipcol + overlap + scrolloff_cols)
     {
@@ -2059,8 +2061,19 @@ adjust_skipcol(void)
        return;  // don't scroll in the other direction now
     }
 
-    int col = curwin->w_virtcol - curwin->w_skipcol + scrolloff_cols;
-    int row = 0;
+    col = curwin->w_virtcol + scrolloff_cols;
+
+    // Avoid adjusting for 'scrolloff' beyond the text line height.
+    if (scrolloff_cols > 0)
+    {
+       int size = win_linetabsize(curwin, curwin->w_topline,
+                                   ml_get(curwin->w_topline), (colnr_T)MAXCOL);
+       size = width1 + width2 * ((size - width1 + width2 - 1) / width2);
+       while (col > size)
+           col -= width2;
+    }
+    col -= curwin->w_skipcol;
+
     if (col >= width1)
     {
        col -= width1;
@@ -2785,7 +2798,9 @@ scroll_cursor_bot(int min_scroll, int set_topbot)
     }
     curwin->w_valid |= VALID_TOPLINE;
 
-    cursor_correct_sms();
+    // Make sure cursor is still visible after adjusting skipcol for "zb".
+    if (set_topbot)
+       cursor_correct_sms();
 }
 
 /*
diff --git a/src/testdir/dumps/Test_smooth_long_6.dump 
b/src/testdir/dumps/Test_smooth_long_6.dump
index 507aa460d..ba48c2825 100644
--- a/src/testdir/dumps/Test_smooth_long_6.dump
+++ b/src/testdir/dumps/Test_smooth_long_6.dump
@@ -3,4 +3,4 @@
 |t|s| |o|f| |t|e|x|t| |w|i|t|h| |l|o|t|s| |o|f| |t|e|x|t| |w|i|t|h| |l|o|t|s| 
|o
 |f| |t|e|x|t| |w|i|t|h| |l|o|t|s| |o|f| |t|e|x|t| |w|i|t|h| |l|o|t|s| |o|f| 
|t|e
 |x|t| |w|i|t|h| |l|o|t|s| |o|f| |t|e|x|t| |w|i|t|h| |l|o|t|s| |o|f| |t|e|x|t| 
|w
-|:|s|e|t| |s|c|r|o|l@1|o| @9|3|,|9|0| @9|6@1|%| 
+| @21|3|,|9|0| @9|6@1|%| 
diff --git a/src/testdir/dumps/Test_smooth_long_7.dump 
b/src/testdir/dumps/Test_smooth_long_7.dump
index 225207ff6..222e0019f 100644
--- a/src/testdir/dumps/Test_smooth_long_7.dump
+++ b/src/testdir/dumps/Test_smooth_long_7.dump
@@ -3,4 +3,4 @@
 |t|s| |o|f| |t|e|x|t| |w|i|t|h| |l|o|t|s| |o|f| |t|e|x|t| |w|i|t|h| |l|o|t|s| 
|o
 |f| |t|e|x|t| |w|i>t|h| |l|o|t|s| |o|f| |t|e|x|t| |w|i|t|h| |l|o|t|s| |o|f| 
|t|e
 |x|t| |w|i|t|h| |l|o|t|s| |o|f| |t|e|x|t| |w|i|t|h| |l|o|t|s| |o|f| |t|e|x|t| 
|w
-|:|s|e|t| |s|c|r|o|l@1|o| @9|3|,|1|7|0| @8|6@1|%| 
+| @21|3|,|1|7|0| @8|6@1|%| 
diff --git a/src/testdir/dumps/Test_smooth_long_scrolloff_1.dump 
b/src/testdir/dumps/Test_smooth_long_scrolloff_1.dump
new file mode 100644
index 000000000..6c1d2231f
--- /dev/null
+++ b/src/testdir/dumps/Test_smooth_long_scrolloff_1.dump
@@ -0,0 +1,8 @@
+| +0&#ffffff0@39
+@40
+@40
+> @39
+@40
+@40
+@40
+@40
diff --git a/src/testdir/dumps/Test_smooth_long_scrolloff_2.dump 
b/src/testdir/dumps/Test_smooth_long_scrolloff_2.dump
new file mode 100644
index 000000000..5b9e20d8d
--- /dev/null
+++ b/src/testdir/dumps/Test_smooth_long_scrolloff_2.dump
@@ -0,0 +1,8 @@
+|<+0#4040ff13#ffffff0@2| +0#0000000&|l|o|n|g|t|w|o| |l|o|n|g|t|w|o| 
|l|o|n|g|t|w|o| |l|o|n|g|t|w|o| |l|o|n|g
+|t|w|o| |l|o|n|g|t|w|o| |l|o|n|g|t|w|o| |l|o|n|g|t|w|o| |l|o|n|g|t|w|o| 
|l|o|n|g
+|t|w|o| |l|o|n|g|t|w|o| |l|o|n|g|t|w|o| |l|o|n|g|t|w|o| |l|o|n|g|t|w|o| 
|l|o|n|g
+|t|w|o| |l|o|n|g|t|w|o| |l|o|n|g|t|w|o| |l|o|n|g|t|w|o| |l|o|n|g|t|w|o| 
|l|o|n|g
+>t|w|o| |l|o|n|g|t|w|o| |l|o|n|g|t|w|o| |l|o|n|g|t|w|o| |l|o|n|g|t|w|o| 
|l|o|n|g
+|t|w|o| |l|o|n|g|t|w|o| |l|o|n|g|t|w|o| |l|o|n|g|t|w|o| |l|o|n|g|t|w|o| 
|l|o|n|g
+|t|w|o| |l|o|n|g|t|w|o| |l|o|n|g|t|w|o| |l|o|n|g|t|w|o| |l|o|n|g|t|w|o| 
|l|o|n|g
+| @39
diff --git a/src/testdir/dumps/Test_smooth_long_scrolloff_3.dump 
b/src/testdir/dumps/Test_smooth_long_scrolloff_3.dump
new file mode 100644
index 000000000..5b9e20d8d
--- /dev/null
+++ b/src/testdir/dumps/Test_smooth_long_scrolloff_3.dump
@@ -0,0 +1,8 @@
+|<+0#4040ff13#ffffff0@2| +0#0000000&|l|o|n|g|t|w|o| |l|o|n|g|t|w|o| 
|l|o|n|g|t|w|o| |l|o|n|g|t|w|o| |l|o|n|g
+|t|w|o| |l|o|n|g|t|w|o| |l|o|n|g|t|w|o| |l|o|n|g|t|w|o| |l|o|n|g|t|w|o| 
|l|o|n|g
+|t|w|o| |l|o|n|g|t|w|o| |l|o|n|g|t|w|o| |l|o|n|g|t|w|o| |l|o|n|g|t|w|o| 
|l|o|n|g
+|t|w|o| |l|o|n|g|t|w|o| |l|o|n|g|t|w|o| |l|o|n|g|t|w|o| |l|o|n|g|t|w|o| 
|l|o|n|g
+>t|w|o| |l|o|n|g|t|w|o| |l|o|n|g|t|w|o| |l|o|n|g|t|w|o| |l|o|n|g|t|w|o| 
|l|o|n|g
+|t|w|o| |l|o|n|g|t|w|o| |l|o|n|g|t|w|o| |l|o|n|g|t|w|o| |l|o|n|g|t|w|o| 
|l|o|n|g
+|t|w|o| |l|o|n|g|t|w|o| |l|o|n|g|t|w|o| |l|o|n|g|t|w|o| |l|o|n|g|t|w|o| 
|l|o|n|g
+| @39
diff --git a/src/testdir/dumps/Test_smooth_long_scrolloff_4.dump 
b/src/testdir/dumps/Test_smooth_long_scrolloff_4.dump
new file mode 100644
index 000000000..6ecdf5b31
--- /dev/null
+++ b/src/testdir/dumps/Test_smooth_long_scrolloff_4.dump
@@ -0,0 +1,8 @@
+|<+0#4040ff13#ffffff0@2| +0#0000000&|l|o|n|g|t|w|o| |l|o|n|g|t|w|o| 
|l|o|n|g|t|w|o| |l|o|n|g|t|w|o| |l|o|n|g
+|t|w|o| |l|o|n|g|t|w|o| |l|o|n|g|t|w|o| |l|o|n|g|t|w|o| |l|o|n|g|t|w|o| 
|l|o|n|g
+|t|w|o| |l|o|n|g|t|w|o| |l|o|n|g|t|w|o| |l|o|n|g|t|w|o| |l|o|n|g|t|w|o| 
|l|o|n|g
+|t|w|o| |l|o|n|g|t|w|o| |l|o|n|g|t|w|o| |l|o|n|g|t|w|o| |l|o|n|g|t|w|o| 
|l|o|n|g
+|t|w|o| |l|o|n|g|t|w|o| |l|o|n|g|t|w|o| |l|o|n|g|t|w|o| |l|o|n|g|t|w|o| 
|l|o|n|g
+>t|w|o| |l|o|n|g|t|w|o| |l|o|n|g|t|w|o| |l|o|n|g|t|w|o| |l|o|n|g|t|w|o| 
|l|o|n|g
+|t|w|o| |l|o|n|g|t|w|o| |l|o|n|g|t|w|o| |l|o|n|g|t|w|o| |l|o|n|g|t|w|o| 
|l|o|n|g
+| @39
diff --git a/src/testdir/dumps/Test_smooth_long_scrolloff_5.dump 
b/src/testdir/dumps/Test_smooth_long_scrolloff_5.dump
new file mode 100644
index 000000000..5ff26d279
--- /dev/null
+++ b/src/testdir/dumps/Test_smooth_long_scrolloff_5.dump
@@ -0,0 +1,8 @@
+|<+0#4040ff13#ffffff0@2| +0#0000000&|l|o|n|g|t|w|o| |l|o|n|g|t|w|o| 
|l|o|n|g|t|w|o| |l|o|n|g|t|w|o| |l|o|n|g
+|t|w|o| |l|o|n|g|t|w|o| |l|o|n|g|t|w|o| |l|o|n|g|t|w|o| |l|o|n|g|t|w|o| 
|l|o|n|g
+|t|w|o| |l|o|n|g|t|w|o| |l|o|n|g|t|w|o| |l|o|n|g|t|w|o| |l|o|n|g|t|w|o| 
|l|o|n|g
+|t|w|o| |l|o|n|g|t|w|o| |l|o|n|g|t|w|o| |l|o|n|g|t|w|o| |l|o|n|g|t|w|o| 
|l|o|n|g
+|t|w|o| |l|o|n|g|t|w|o| |l|o|n|g|t|w|o| |l|o|n|g|t|w|o| |l|o|n|g|t|w|o| 
|l|o|n|g
+|t|w|o| |l|o|n|g|t|w|o| |l|o|n|g|t|w|o| |l|o|n|g|t|w|o| |l|o|n|g|t|w|o| 
|l|o|n|g
+>t|w|o| |l|o|n|g|t|w|o| |l|o|n|g|t|w|o| |l|o|n|g|t|w|o| |l|o|n|g|t|w|o| 
|l|o|n|g
+| @39
diff --git a/src/testdir/dumps/Test_smooth_long_scrolloff_6.dump 
b/src/testdir/dumps/Test_smooth_long_scrolloff_6.dump
new file mode 100644
index 000000000..2ef87da37
--- /dev/null
+++ b/src/testdir/dumps/Test_smooth_long_scrolloff_6.dump
@@ -0,0 +1,8 @@
+|<+0#4040ff13#ffffff0@2| +0#0000000&|l|o|n|g|t|w|o| |l|o|n|g|t|w|o| 
|l|o|n|g|t|w|o| |l|o|n|g|t|w|o| |l|o|n|g
+|t|w|o| |l|o|n|g|t|w|o| |l|o|n|g|t|w|o| |l|o|n|g|t|w|o| |l|o|n|g|t|w|o| 
|l|o|n|g
+|t|w|o| |l|o|n|g|t|w|o| |l|o|n|g|t|w|o| |l|o|n|g|t|w|o| |l|o|n|g|t|w|o| 
|l|o|n|g
+|t|w|o| |l|o|n|g|t|w|o| |l|o|n|g|t|w|o| |l|o|n|g|t|w|o| |l|o|n|g|t|w|o| 
|l|o|n|g
+|t|w|o| |l|o|n|g|t|w|o| |l|o|n|g|t|w|o| |l|o|n|g|t|w|o| |l|o|n|g|t|w|o| 
|l|o|n|g
+>t|h|r|e@1| @34
+|f|o|u|r| @35
+@40
diff --git a/src/testdir/dumps/Test_smooth_long_scrolloff_7.dump 
b/src/testdir/dumps/Test_smooth_long_scrolloff_7.dump
new file mode 100644
index 000000000..c21c0229a
--- /dev/null
+++ b/src/testdir/dumps/Test_smooth_long_scrolloff_7.dump
@@ -0,0 +1,8 @@
+| +0&#ffffff0@39
+@40
+@40
+@40
+@40
+@40
+> @39
+@40
diff --git a/src/testdir/test_scroll_opt.vim b/src/testdir/test_scroll_opt.vim
index da9e4a137..fa1d032c2 100644
--- a/src/testdir/test_scroll_opt.vim
+++ b/src/testdir/test_scroll_opt.vim
@@ -1153,4 +1153,39 @@ func Test_smoothscroll_long_line_zb()
   bwipe!
 endfunc
 
+func Test_smooth_long_scrolloff()
+  CheckScreendump
+
+  let lines =<< trim END
+    set smoothscroll scrolloff=3
+    call setline(1, ['one', 'two long'->repeat(100), 'three', 'four', 'five', 
'six'])
+  END
+  call writefile(lines, 'XSmoothLongScrolloff', 'D')
+  let buf = RunVimInTerminal('-u NONE -S XSmoothLongScrolloff', #{rows: 8, 
cols: 40})
+  "FIXME: empty screen due to reset_skipcol()/curs_columns() shenanigans
+  call term_sendkeys(buf, ":norm j601|\<CR>")
+  call VerifyScreenDump(buf, 'Test_smooth_long_scrolloff_1', {})
+
+  call term_sendkeys(buf, "gj")
+  call VerifyScreenDump(buf, 'Test_smooth_long_scrolloff_2', {})
+
+  call term_sendkeys(buf, "gj")
+  call VerifyScreenDump(buf, 'Test_smooth_long_scrolloff_3', {})
+
+  call term_sendkeys(buf, "gj")
+  call VerifyScreenDump(buf, 'Test_smooth_long_scrolloff_4', {})
+
+  call term_sendkeys(buf, "gj")
+  call VerifyScreenDump(buf, 'Test_smooth_long_scrolloff_5', {})
+
+  call term_sendkeys(buf, "gj")
+  call VerifyScreenDump(buf, 'Test_smooth_long_scrolloff_6', {})
+
+  call term_sendkeys(buf, "gk")
+  "FIXME: empty screen due to reset_skipcol()/curs_columns() shenanigans
+  call VerifyScreenDump(buf, 'Test_smooth_long_scrolloff_7', {})
+
+  call StopVimInTerminal(buf)
+endfunc
+
 " vim: shiftwidth=2 sts=2 expandtab
diff --git a/src/version.c b/src/version.c
index b79693c6a..c0cf43cdf 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 */
+/**/
+    414,
 /**/
     413,
 /**/

-- 
-- 
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/E1s7gLP-005wBg-3Q%40256bit.org.

Reply via email to