aboutsummaryrefslogtreecommitdiffstats
path: root/src/window.c
diff options
context:
space:
mode:
authorEli Zaretskii2016-01-18 18:19:50 +0200
committerEli Zaretskii2016-01-18 18:19:50 +0200
commitb2eb6911dc8af51a5a9f8b7a011cf63c724d533b (patch)
treeffffe94026bc497de4cba545d98aad7e46a28d29 /src/window.c
parent687a64f637253b5ffbbed3c4f620aabe411e1a17 (diff)
downloademacs-b2eb6911dc8af51a5a9f8b7a011cf63c724d533b.tar.gz
emacs-b2eb6911dc8af51a5a9f8b7a011cf63c724d533b.zip
Fix scrolling under scroll-preserve-screen-position and margins
* src/window.c (window_scroll_pixel_based): When setting point to preserve screen coordinates, don't let cursor enter either of the two scroll margins. Fix incorrect usage of WINDOW_WANTS_HEADER_LINE_P and use WINDOW_HEADER_LINE_HEIGHT instead of CURRENT_HEADER_LINE_HEIGHT. (Bug#22395)
Diffstat (limited to 'src/window.c')
-rw-r--r--src/window.c43
1 files changed, 28 insertions, 15 deletions
diff --git a/src/window.c b/src/window.c
index bbe47c7255a..1a75342471f 100644
--- a/src/window.c
+++ b/src/window.c
@@ -4981,27 +4981,34 @@ window_scroll_pixel_based (Lisp_Object window, int n, bool whole, bool noerror)
4981 4981
4982 if (n > 0) 4982 if (n > 0)
4983 { 4983 {
4984 int last_y = it.last_visible_y - this_scroll_margin - 1;
4985
4984 /* We moved the window start towards ZV, so PT may be now 4986 /* We moved the window start towards ZV, so PT may be now
4985 in the scroll margin at the top. */ 4987 in the scroll margin at the top. */
4986 move_it_to (&it, PT, -1, -1, -1, MOVE_TO_POS); 4988 move_it_to (&it, PT, -1, -1, -1, MOVE_TO_POS);
4987 if (IT_CHARPOS (it) == PT && it.current_y >= this_scroll_margin 4989 if (IT_CHARPOS (it) == PT
4990 && it.current_y >= this_scroll_margin
4991 && it.current_y <= last_y - WINDOW_HEADER_LINE_HEIGHT (w)
4988 && (NILP (Vscroll_preserve_screen_position) 4992 && (NILP (Vscroll_preserve_screen_position)
4989 || EQ (Vscroll_preserve_screen_position, Qt))) 4993 || EQ (Vscroll_preserve_screen_position, Qt)))
4990 /* We found PT at a legitimate height. Leave it alone. */ 4994 /* We found PT at a legitimate height. Leave it alone. */
4991 ; 4995 ;
4992 else if (window_scroll_pixel_based_preserve_y >= 0)
4993 {
4994 /* If we have a header line, take account of it.
4995 This is necessary because we set it.current_y to 0, above. */
4996 move_it_to (&it, -1,
4997 window_scroll_pixel_based_preserve_x,
4998 (window_scroll_pixel_based_preserve_y
4999 - WINDOW_WANTS_HEADER_LINE_P (w)),
5000 -1, MOVE_TO_Y | MOVE_TO_X);
5001 SET_PT_BOTH (IT_CHARPOS (it), IT_BYTEPOS (it));
5002 }
5003 else 4996 else
5004 { 4997 {
4998 if (window_scroll_pixel_based_preserve_y >= 0)
4999 {
5000 /* Don't enter the scroll margin at the end of the window. */
5001 int goal_y = min (last_y, window_scroll_pixel_based_preserve_y);
5002
5003 /* If we have a header line, take account of it. This
5004 is necessary because we set it.current_y to 0, above. */
5005 move_it_to (&it, -1,
5006 window_scroll_pixel_based_preserve_x,
5007 goal_y - WINDOW_HEADER_LINE_HEIGHT (w),
5008 -1, MOVE_TO_Y | MOVE_TO_X);
5009 }
5010
5011 /* Get out of the scroll margin at the top of the window. */
5005 while (it.current_y < this_scroll_margin) 5012 while (it.current_y < this_scroll_margin)
5006 { 5013 {
5007 int prev = it.current_y; 5014 int prev = it.current_y;
@@ -5025,7 +5032,7 @@ window_scroll_pixel_based (Lisp_Object window, int n, bool whole, bool noerror)
5025 /* We moved the window start towards BEGV, so PT may be now 5032 /* We moved the window start towards BEGV, so PT may be now
5026 in the scroll margin at the bottom. */ 5033 in the scroll margin at the bottom. */
5027 move_it_to (&it, PT, -1, 5034 move_it_to (&it, PT, -1,
5028 (it.last_visible_y - CURRENT_HEADER_LINE_HEIGHT (w) 5035 (it.last_visible_y - WINDOW_HEADER_LINE_HEIGHT (w)
5029 - this_scroll_margin - 1), 5036 - this_scroll_margin - 1),
5030 -1, 5037 -1,
5031 MOVE_TO_POS | MOVE_TO_Y); 5038 MOVE_TO_POS | MOVE_TO_Y);
@@ -5076,14 +5083,20 @@ window_scroll_pixel_based (Lisp_Object window, int n, bool whole, bool noerror)
5076 ; 5083 ;
5077 else if (window_scroll_pixel_based_preserve_y >= 0) 5084 else if (window_scroll_pixel_based_preserve_y >= 0)
5078 { 5085 {
5086 int goal_y = min (it.last_visible_y - this_scroll_margin - 1,
5087 window_scroll_pixel_based_preserve_y);
5088
5089 /* Don't let the preserved screen Y coordinate put us inside
5090 any of the two margins. */
5091 if (goal_y < this_scroll_margin)
5092 goal_y = this_scroll_margin;
5079 SET_TEXT_POS_FROM_MARKER (start, w->start); 5093 SET_TEXT_POS_FROM_MARKER (start, w->start);
5080 start_display (&it, w, start); 5094 start_display (&it, w, start);
5081 /* It would be wrong to subtract CURRENT_HEADER_LINE_HEIGHT 5095 /* It would be wrong to subtract CURRENT_HEADER_LINE_HEIGHT
5082 here because we called start_display again and did not 5096 here because we called start_display again and did not
5083 alter it.current_y this time. */ 5097 alter it.current_y this time. */
5084 move_it_to (&it, -1, window_scroll_pixel_based_preserve_x, 5098 move_it_to (&it, -1, window_scroll_pixel_based_preserve_x,
5085 window_scroll_pixel_based_preserve_y, -1, 5099 goal_y, -1, MOVE_TO_Y | MOVE_TO_X);
5086 MOVE_TO_Y | MOVE_TO_X);
5087 SET_PT_BOTH (IT_CHARPOS (it), IT_BYTEPOS (it)); 5100 SET_PT_BOTH (IT_CHARPOS (it), IT_BYTEPOS (it));
5088 } 5101 }
5089 else 5102 else