Mercurial > emacs
comparison src/xdisp.c @ 40297:83a67b746289
(move_it_vertically_backward): Compute line height
differently. Add heuristic to try to be more compatible to 20.x.
author | Gerd Moellmann <gerd@gnu.org> |
---|---|
date | Thu, 25 Oct 2001 10:07:01 +0000 |
parents | 568fe11a570e |
children | e2acdd1b8bb7 |
comparison
equal
deleted
inserted
replaced
40296:a5332cff58ba | 40297:83a67b746289 |
---|---|
5309 void | 5309 void |
5310 move_it_vertically_backward (it, dy) | 5310 move_it_vertically_backward (it, dy) |
5311 struct it *it; | 5311 struct it *it; |
5312 int dy; | 5312 int dy; |
5313 { | 5313 { |
5314 int nlines, h, line_height; | 5314 int nlines, h; |
5315 struct it it2; | 5315 struct it it2, it3; |
5316 int start_pos = IT_CHARPOS (*it); | 5316 int start_pos = IT_CHARPOS (*it); |
5317 | 5317 |
5318 xassert (dy >= 0); | 5318 xassert (dy >= 0); |
5319 | 5319 |
5320 /* Estimate how many newlines we must move back. */ | 5320 /* Estimate how many newlines we must move back. */ |
5340 it2 = *it; | 5340 it2 = *it; |
5341 it2.max_ascent = it2.max_descent = 0; | 5341 it2.max_ascent = it2.max_descent = 0; |
5342 move_it_to (&it2, start_pos, -1, -1, it2.vpos + 1, | 5342 move_it_to (&it2, start_pos, -1, -1, it2.vpos + 1, |
5343 MOVE_TO_POS | MOVE_TO_VPOS); | 5343 MOVE_TO_POS | MOVE_TO_VPOS); |
5344 xassert (IT_CHARPOS (*it) >= BEGV); | 5344 xassert (IT_CHARPOS (*it) >= BEGV); |
5345 line_height = it2.max_ascent + it2.max_descent; | 5345 it3 = it2; |
5346 | 5346 |
5347 move_it_to (&it2, start_pos, -1, -1, -1, MOVE_TO_POS); | 5347 move_it_to (&it2, start_pos, -1, -1, -1, MOVE_TO_POS); |
5348 xassert (IT_CHARPOS (*it) >= BEGV); | 5348 xassert (IT_CHARPOS (*it) >= BEGV); |
5349 h = it2.current_y - it->current_y; | 5349 h = it2.current_y - it->current_y; |
5350 nlines = it2.vpos - it->vpos; | 5350 nlines = it2.vpos - it->vpos; |
5364 else if (nlines) | 5364 else if (nlines) |
5365 { | 5365 { |
5366 /* The y-position we try to reach. Note that h has been | 5366 /* The y-position we try to reach. Note that h has been |
5367 subtracted in front of the if-statement. */ | 5367 subtracted in front of the if-statement. */ |
5368 int target_y = it->current_y + h - dy; | 5368 int target_y = it->current_y + h - dy; |
5369 | 5369 int y0 = it3.current_y; |
5370 int y1 = line_bottom_y (&it3); | |
5371 int line_height = y1 - y0; | |
5372 | |
5370 /* If we did not reach target_y, try to move further backward if | 5373 /* If we did not reach target_y, try to move further backward if |
5371 we can. If we moved too far backward, try to move forward. */ | 5374 we can. If we moved too far backward, try to move forward. */ |
5372 if (target_y < it->current_y | 5375 if (target_y < it->current_y |
5376 /* This is heuristic. In a window that's 3 lines high, with | |
5377 a line height of 13 pixels each, recentering with point | |
5378 on the bottom line will try to move -39/2 = 19 pixels | |
5379 backward. Try to avoid moving into the first line. */ | |
5380 && it->current_y - target_y > line_height / 2 | |
5373 && IT_CHARPOS (*it) > BEGV) | 5381 && IT_CHARPOS (*it) > BEGV) |
5374 { | 5382 { |
5375 move_it_vertically (it, target_y - it->current_y); | 5383 move_it_vertically (it, target_y - it->current_y); |
5376 xassert (IT_CHARPOS (*it) >= BEGV); | 5384 xassert (IT_CHARPOS (*it) >= BEGV); |
5377 } | 5385 } |