From: Eli Zaretskii Date: Tue, 12 Feb 2013 16:43:09 +0000 (+0200) Subject: Fix cursor positioning near scroll margin at top of window. X-Git-Tag: emacs-24.3.90~173^2~7^2~71 X-Git-Url: http://git.eshelyaron.com/gitweb/?a=commitdiff_plain;h=c4131562319d3529841136d236ac39fb1e3d2b7c;p=emacs.git Fix cursor positioning near scroll margin at top of window. src/xdisp.c (try_scrolling): Scroll text up more if point is too close to ZV and inside the scroll margin. This makes sure point is moved outside the scroll margin in these cases. --- diff --git a/src/ChangeLog b/src/ChangeLog index fb4cc723646..05737bb1194 100644 --- a/src/ChangeLog +++ b/src/ChangeLog @@ -6,6 +6,9 @@ it->region_beg_charpos, not to -1. This fixes redisplay optimization when cursor is moved up after M->. (Bug#13623) (Bug#13626) + (try_scrolling): Scroll text up more if point is too close to ZV + and inside the scroll margin. This makes sure point is moved + outside the scroll margin in these cases. * window.h (struct window): region_showing can no longer be negative. diff --git a/src/xdisp.c b/src/xdisp.c index ca3f968afa7..d2d4b3bbb79 100644 --- a/src/xdisp.c +++ b/src/xdisp.c @@ -14604,14 +14604,24 @@ try_scrolling (Lisp_Object window, int just_this_one_p, else { struct text_pos scroll_margin_pos = startp; + int y_offset = 0; /* See if point is inside the scroll margin at the top of the window. */ if (this_scroll_margin) { + int y_start; + start_display (&it, w, startp); + y_start = it.current_y; move_it_vertically (&it, this_scroll_margin); scroll_margin_pos = it.current.pos; + /* If we didn't move enough before hitting ZV, request + additional amount of scroll, to move point out of the + scroll margin. */ + if (IT_CHARPOS (it) == ZV + && it.current_y - y_start < this_scroll_margin) + y_offset = this_scroll_margin - (it.current_y - y_start); } if (PT < CHARPOS (scroll_margin_pos)) @@ -14638,6 +14648,9 @@ try_scrolling (Lisp_Object window, int just_this_one_p, || IT_CHARPOS (it) < CHARPOS (scroll_margin_pos)) return SCROLLING_FAILED; + /* Additional scroll for when ZV was too close to point. */ + dy += y_offset; + /* Compute new window start. */ start_display (&it, w, startp);