Subject: bug#28936: move_it_in_display_line_to returns MOVE_POS_MATCH_OR_ZV before ZV

From: Eli Zaretskii <[email-masked]>
Date: Sun, 22 Oct 2017 21:30:45 +0300

> Date:  Sun, 22 Oct 2017 11:05:45 -0700
> From:  Keith David Bershatsky <[email-masked]>
> Cc:  [email-masked]
> 
> Thank you, Eli, for looking into #28936.

I don't think there's any bug here.

> With respect to `move_it_in_display_line`, I was not able to reliably land on `it.first_visible_x + lnum_pixel_width` when horizontal scrolling to the right AND text truncated on the left.  IT overshoots the target by one text character.

This means you have an off-by-one error, probably because you are
not computing the target X coordinate correctly.  The mistake I show
below is probably the same mistake you do elsewhere.

>   while (it->current_x + it->pixel_width <= target_x

This condition will cause the iterator to attempt to get to the
character _after_ point, where it will hit ZV.  So what you see, viz.:

> STEP #5:  Observe that the result is "1" when it should be "2".

is expected.  You should change the condition to this:

   while (it->current_x < target_x