From 2e7402b760576b54a326fca593c948a73bc3d6d0 Mon Sep 17 00:00:00 2001 From: Eli Zaretskii Date: Tue, 15 Dec 2020 19:34:16 +0200 Subject: [PATCH] Fix C-n/C-p when a line starts with an image * src/xdisp.c (move_it_to): Handle the case where the second call to move_it_in_display_line_to under MOVE_TO_Y takes us farther from TO_CHARPOS than the first call. This fixes values returned by pos-visible-in-window-p and posn-at-point when the screen line starts with invisible text followed by an image. (Bug#9092) --- src/xdisp.c | 22 +++++++++++++++++++++- 1 file changed, 21 insertions(+), 1 deletion(-) diff --git a/src/xdisp.c b/src/xdisp.c index 699183f3f59..0fd5ec5ec56 100644 --- a/src/xdisp.c +++ b/src/xdisp.c @@ -9957,7 +9957,27 @@ move_it_to (struct it *it, ptrdiff_t to_charpos, int to_x, int to_y, int to_vpos { skip = skip2; if (skip == MOVE_POS_MATCH_OR_ZV) - reached = 7; + { + reached = 7; + /* If the last move_it_in_display_line_to call + took us away from TO_CHARPOS, back up to the + previous position, as it is a better + approximation of TO_CHARPOS. (Note that we + could have both positions after TO_CHARPOS or + both positions before it, due to bidi + reordering.) */ + if (IT_CHARPOS (*it) != to_charpos + && ((IT_CHARPOS (it_backup) > to_charpos) + == (IT_CHARPOS (*it) > to_charpos))) + { + int max_ascent = it->max_ascent; + int max_descent = it->max_descent; + + RESTORE_IT (it, &it_backup, backup_data); + it->max_ascent = max_ascent; + it->max_descent = max_descent; + } + } } } else -- 2.39.2