Subject: [PATCH] WIP: Fix incorrect handling of overlays in `vertical-motion'

From: Sergio Pastor Pérez <[email-masked]>
Date: Tue, 19 Aug 2025 21:21:58 +0200

FIXME: if multiple lines with multi-line overlays are present, going
upwards jumps to the first one of them, instead of the previous line at
the right column.

* src/indent.c (vertical-motion): Ensure multi-line overlay handling
logic captures upward motions.
---
 src/indent.c | 7 ++++---
 1 file changed, 4 insertions(+), 3 deletions(-)

diff --git a/src/indent.c b/src/indent.c
index b4f3c349dc5..c1c32824dad 100644
--- a/src/indent.c
+++ b/src/indent.c
@@ -2513,15 +2513,16 @@ line (if such column exists on that line, that is).  If the line is
 	     and then reposition point at the requested X coordinate;
 	     if we don't, the cursor will be placed just after the
 	     string, which might not be the requested column.  */
-	  if (nlines >= 0 && it.area == TEXT_AREA)
+	  if (nlines != 0 && it.area == TEXT_AREA)
 	    {
 	      while (it.method == GET_FROM_STRING
-		     && !it.string_from_display_prop_p
 		     && memchr (SSDATA (it.string) + IT_STRING_BYTEPOS (it),
 				'\n',
 				SBYTES (it.string) - IT_STRING_BYTEPOS (it)))
 		{
-		  move_it_by_lines (&it, 1);
+		  int direction = (nlines > 0) ? 1 : -1;
+
+		  move_it_by_lines (&it, direction);
 		  move_it_in_display_line (&it, ZV, first_x + to_x, MOVE_TO_X);
 		}
 	    }
-- 
2.50.1