changeset 56118:6fbabfb26a3c

(try_cursor_movement): Exclude header line from scroll margin at top of window. (try_window_reusing_current_matrix): Calculate proper cursor position after scrolling up with non-zero scroll margin, as the old cursor position corresponds to value of PT before executing this command. (try_window_id): Consider scroll margin at bottom of window too; otherwise we fail to scroll when hl-line-mode is enabled.
author Kim F. Storm <storm@cua.dk>
date Tue, 15 Jun 2004 10:35:05 +0000
parents 75f76430cc6c
children 23a626038a46
files src/xdisp.c
diffstat 1 files changed, 35 insertions(+), 9 deletions(-) [+]
line wrap: on
line diff
--- a/src/xdisp.c	Tue Jun 15 10:33:15 2004 +0000
+++ b/src/xdisp.c	Tue Jun 15 10:35:05 2004 +0000
@@ -11267,7 +11267,7 @@
       && (FRAME_WINDOW_P (f)
 	  || !overlay_arrow_in_current_buffer_p ()))
     {
-      int this_scroll_margin;
+      int this_scroll_margin, top_scroll_margin;
       struct glyph_row *row = NULL;
 
 #if GLYPH_DEBUG
@@ -11280,6 +11280,10 @@
       this_scroll_margin = min (this_scroll_margin, WINDOW_TOTAL_LINES (w) / 4);
       this_scroll_margin *= FRAME_LINE_HEIGHT (f);
 
+      top_scroll_margin = this_scroll_margin;
+      if (WINDOW_WANTS_HEADER_LINE_P (w))
+	top_scroll_margin += CURRENT_HEADER_LINE_HEIGHT (w);
+
       /* Start with the row the cursor was displayed during the last
 	 not paused redisplay.  Give up if that row is not valid.  */
       if (w->last_cursor.vpos < 0
@@ -11340,7 +11344,7 @@
 		     && (MATRIX_ROW_START_CHARPOS (row) > PT
 			 || (MATRIX_ROW_START_CHARPOS (row) == PT
 			     && MATRIX_ROW_STARTS_IN_MIDDLE_OF_CHAR_P (row)))
-		     && (row->y > this_scroll_margin
+		     && (row->y > top_scroll_margin
 			 || CHARPOS (startp) == BEGV))
 		{
 		  xassert (row->enabled_p);
@@ -11368,7 +11372,7 @@
 		++row;
 
 	      /* If within the scroll margin, scroll.  */
-	      if (row->y < this_scroll_margin
+	      if (row->y < top_scroll_margin
 		  && CHARPOS (startp) != BEGV)
 		scroll_p = 1;
 	    }
@@ -12538,9 +12542,8 @@
 	 position.  */
       if (pt_row)
 	{
-	  w->cursor.vpos -= MATRIX_ROW_VPOS (first_reusable_row,
-					     w->current_matrix);
-	  w->cursor.y -= first_reusable_row->y;
+	  w->cursor.vpos -= nrows_scrolled;
+	  w->cursor.y -= first_reusable_row->y - start_row->y;
 	}
 
       /* Scroll the display.  */
@@ -12585,6 +12588,29 @@
       for (row -= nrows_scrolled; row < bottom_row; ++row)
 	row->enabled_p = 0;
 
+      /* Point may have moved to a different line, so we cannot assume that
+	 the previous cursor position is valid; locate the correct row.  */
+      if (pt_row)
+	{
+	  for (row = MATRIX_ROW (w->current_matrix, w->cursor.vpos);
+	       row < bottom_row && PT >= MATRIX_ROW_END_CHARPOS (row);
+	       row++)
+	    {
+	      w->cursor.vpos++;
+	      w->cursor.y = row->y;
+	    }
+	  if (row < bottom_row)
+	    {
+	      struct glyph *glyph = row->glyphs[TEXT_AREA] + w->cursor.hpos;
+	      while (glyph->charpos < PT)
+		{
+		  w->cursor.hpos++;
+		  w->cursor.x += glyph->pixel_width;
+		  glyph++;
+		}
+	    }
+	}
+
       /* Adjust window end.  A null value of last_text_row means that
 	 the window end is in reused rows which in turn means that
 	 only its vpos can have changed.  */
@@ -13368,9 +13394,9 @@
 
     if ((w->cursor.y < this_scroll_margin
 	 && CHARPOS (start) > BEGV)
-	/* Don't take scroll margin into account at the bottom because
-	   old redisplay didn't do it either.  */
-	|| w->cursor.y + cursor_height > it.last_visible_y)
+	/* 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_height + this_scroll_margin > it.last_visible_y)
       {
 	w->cursor.vpos = -1;
 	clear_glyph_matrix (w->desired_matrix);