]> git.eshelyaron.com Git - emacs.git/commitdiff
Fix 'posn-at-point' near some overlays
authorEli Zaretskii <eliz@gnu.org>
Thu, 25 Nov 2021 13:06:08 +0000 (15:06 +0200)
committerEli Zaretskii <eliz@gnu.org>
Thu, 25 Nov 2021 13:06:08 +0000 (15:06 +0200)
* src/xdisp.c (pos_visible_p): Fix 'posn-at-point' for positions
just after a display property that draws a fringe bitmap.
(Bug#52097)

src/xdisp.c

index 34add807986fe24889ec976d7be028292cbce7ee..4642541823cc283f303b185e5f907893b09877c3 100644 (file)
@@ -1992,7 +1992,17 @@ pos_visible_p (struct window *w, ptrdiff_t charpos, int *x, int *y,
            }
 
          *x = top_x;
-         *y = max (top_y + max (0, it.max_ascent - it.ascent), window_top_y);
+         /* The condition below is a heuristic fix for the situation
+            where move_it_to stops just after finishing the display
+            of a fringe bitmap, which resets it.ascent to zero, and
+            thus causes Y to be offset by it.max_ascent.  */
+         if (it.ascent == 0 && it.what == IT_IMAGE
+             && it.method != GET_FROM_IMAGE
+             && it.image_id < 0
+             && it.max_ascent > 0)
+           *y = max (top_y, window_top_y);
+         else
+           *y = max (top_y + max (0, it.max_ascent - it.ascent), window_top_y);
          *rtop = max (0, window_top_y - top_y);
          *rbot = max (0, bottom_y - it.last_visible_y);
          *rowh = max (0, (min (bottom_y, it.last_visible_y)
@@ -2020,7 +2030,13 @@ pos_visible_p (struct window *w, ptrdiff_t charpos, int *x, int *y,
          RESTORE_IT (&it2, &it2, it2data);
          move_it_to (&it2, charpos, -1, -1, -1, MOVE_TO_POS);
          *x = it2.current_x;
-         *y = it2.current_y + it2.max_ascent - it2.ascent;
+         if (it2.ascent == 0 && it2.what == IT_IMAGE
+             && it2.method != GET_FROM_IMAGE
+             && it2.image_id < 0
+             && it2.max_ascent > 0)
+           *y = it2.current_y;
+         else
+           *y = it2.current_y + it2.max_ascent - it2.ascent;
          *rtop = max (0, -it2.current_y);
          *rbot = max (0, ((it2.current_y + it2.max_ascent + it2.max_descent)
                           - it.last_visible_y));