]> git.eshelyaron.com Git - emacs.git/commitdiff
Fix C-n/C-p when a line starts with an image
authorEli Zaretskii <eliz@gnu.org>
Tue, 15 Dec 2020 17:34:16 +0000 (19:34 +0200)
committerEli Zaretskii <eliz@gnu.org>
Tue, 15 Dec 2020 17:34:16 +0000 (19:34 +0200)
* 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

index 699183f3f59d5744fa0771f47f9ea0a0579f5c2b..0fd5ec5ec56ca9cd86f410fb966a423462ead8e5 100644 (file)
@@ -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