&& (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
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
&& (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);
++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;
}
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. */
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. */
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);