From: Eli Zaretskii <eliz@gnu.org>
Date: Mon, 1 May 2023 12:27:21 +0000 (+0300)
Subject: Fix vertical-motion when tab-line is displayed in a window
X-Git-Tag: emacs-29.0.91~65
X-Git-Url: http://git.eshelyaron.com/gitweb/?a=commitdiff_plain;h=46392c1623bc3f9764b8c7df293a89fcd47ab0ad;p=emacs.git

Fix vertical-motion when tab-line is displayed in a window

* src/xdisp.c (try_window, try_window_id): Account for tab-line,
if present, when converting scroll-margin at the top of the window
to vertical pixel coordinate.  (Bug#63201)
---

diff --git a/src/xdisp.c b/src/xdisp.c
index 8e265fb5a49..43847544396 100644
--- a/src/xdisp.c
+++ b/src/xdisp.c
@@ -20600,6 +20600,8 @@ try_window (Lisp_Object window, struct text_pos pos, int flags)
       int bot_scroll_margin = top_scroll_margin;
       if (window_wants_header_line (w))
 	top_scroll_margin += CURRENT_HEADER_LINE_HEIGHT (w);
+      if (window_wants_tab_line (w))
+	top_scroll_margin += CURRENT_TAB_LINE_HEIGHT (w);
       start_display (&it, w, pos);
 
       if ((w->cursor.y >= 0
@@ -21944,17 +21946,23 @@ try_window_id (struct window *w)
 
   /* Don't let the cursor end in the scroll margins.  */
   {
-    int this_scroll_margin = window_scroll_margin (w, MARGIN_IN_PIXELS);
+    int top_scroll_margin = window_scroll_margin (w, MARGIN_IN_PIXELS);
+    int bot_scroll_margin = top_scroll_margin;
     int cursor_height = MATRIX_ROW (w->desired_matrix, w->cursor.vpos)->height;
 
-    if ((w->cursor.y < this_scroll_margin
+    if (window_wants_header_line (w))
+      top_scroll_margin += CURRENT_HEADER_LINE_HEIGHT (w);
+    if (window_wants_tab_line (w))
+      top_scroll_margin += CURRENT_TAB_LINE_HEIGHT (w);
+
+    if ((w->cursor.y < top_scroll_margin
 	 && CHARPOS (start) > BEGV)
 	/* Old redisplay didn't take scroll margin into account at the bottom,
 	   but then global-hl-line-mode doesn't scroll.  KFS 2004-06-14 */
 	|| (w->cursor.y
 	    + (cursor_row_fully_visible_p (w, false, true, true)
 	       ? 1
-	       : cursor_height + this_scroll_margin)) > it.last_visible_y)
+	       : cursor_height + bot_scroll_margin)) > it.last_visible_y)
       {
 	w->cursor.vpos = -1;
 	clear_glyph_matrix (w->desired_matrix);