patch 9.1.1330: may receive E315 in terminal

Problem:  may receive E315 in terminal
Solution: call check_cursor() (Hirohito Higashi)

fixes: #16024
fixes: #16211
fixes: #17099
closes: #17170

Signed-off-by: Hirohito Higashi <h.east.727@gmail.com>
Signed-off-by: Christian Brabandt <cb@256bit.org>
diff --git a/src/mouse.c b/src/mouse.c
index 3bdb102..4e10e72 100644
--- a/src/mouse.c
+++ b/src/mouse.c
@@ -1902,16 +1902,6 @@
 	    // Drag the status line
 	    count = row - W_WINROW(dragwin) - dragwin->w_height + 1
 							     - on_status_line;
-#ifdef FEAT_TERMINAL
-	    if (bt_terminal(dragwin->w_buffer))
-	    {
-		win_T *curwin_save = curwin;
-		curwin = dragwin;
-		update_topline();
-		validate_cursor();
-		curwin = curwin_save;
-	    }
-#endif
 	    win_drag_status_line(dragwin, count);
 	    did_drag |= count;
 	}
diff --git a/src/terminal.c b/src/terminal.c
index eb27fa5..88791b8 100644
--- a/src/terminal.c
+++ b/src/terminal.c
@@ -3454,8 +3454,23 @@
 	    (sb_line_T *)gap->ga_data + todo,
 	    sizeof(sb_line_T) * gap->ga_len);
     if (update_buffer)
+    {
+	win_T	    *curwin_save = curwin;
+	win_T	    *wp = NULL;
+
 	term->tl_scrollback_scrolled -= todo;
 
+	FOR_ALL_WINDOWS(wp)
+	{
+	    if (wp->w_buffer == term->tl_buffer)
+	    {
+		curwin = wp;
+		check_cursor();
+	    }
+	}
+	curwin = curwin_save;
+    }
+
     // make sure cursor is on a valid line
     if (curbuf == term->tl_buffer)
 	check_cursor();
diff --git a/src/version.c b/src/version.c
index 60c5243..048788e 100644
--- a/src/version.c
+++ b/src/version.c
@@ -705,6 +705,8 @@
 static int included_patches[] =
 {   /* Add new patch number below this line */
 /**/
+    1330,
+/**/
     1329,
 /**/
     1328,
diff --git a/src/window.c b/src/window.c
index 9ea6810..1eb32bc 100644
--- a/src/window.c
+++ b/src/window.c
@@ -5643,10 +5643,6 @@
 	did_decrement = TRUE;
     }
 #endif
-#ifdef FEAT_TERMINAL
-    if (bt_terminal(curwin->w_buffer))
-	update_topline();
-#endif
 
     win_fix_current_dir();