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 <luukvbaal@gmail.com>
Signed-off-by: Christian Brabandt <cb@256bit.org>
diff --git a/src/move.c b/src/move.c
index dd23268..71654dd 100644
--- a/src/move.c
+++ b/src/move.c
@@ -2027,6 +2027,8 @@
     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 @@
     }
 
     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 @@
 	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 @@
     }
     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();
 }
 
 /*