From ad3c1639757e8b5aefb490426ca44dad08b74130 Mon Sep 17 00:00:00 2001
From: Eli Zaretskii <eliz@gnu.org>
Date: Thu, 7 Jul 2011 20:48:51 +0300
Subject: [PATCH] Fix another bug with cursor motion around display properties.
 Still not quite there yet.

 src/xdisp.c (find_row_edges): If ROW->start.pos gives position
 smaller than min_pos, use it as ROW->minpos.  (Bug#7616)
---
 src/ChangeLog | 7 ++++++-
 src/xdisp.c   | 9 +++++----
 2 files changed, 11 insertions(+), 5 deletions(-)

diff --git a/src/ChangeLog b/src/ChangeLog
index 55ff323ab57..74a684df45e 100644
--- a/src/ChangeLog
+++ b/src/ChangeLog
@@ -1,3 +1,8 @@
+2011-07-07  Eli Zaretskii  <eliz@gnu.org>
+
+	* xdisp.c (find_row_edges): If ROW->start.pos gives position
+	smaller than min_pos, use it as ROW->minpos.  (Bug#7616)
+
 2011-07-05  Eli Zaretskii  <eliz@gnu.org>
 
 	* dispnew.c (buffer_posn_from_coords): Save and restore the bidi
@@ -33,7 +38,7 @@
 2011-07-02  Eli Zaretskii  <eliz@gnu.org>
 
 	* xdisp.c (reseat_1): Call bidi_init_it to resync the bidi
-	iterator with IT's position.
+	iterator with IT's position.  (Bug#7616)
 	(handle_stop, back_to_previous_visible_line_start, reseat_1):
 	Reset the from_disp_prop_p flag.
 
diff --git a/src/xdisp.c b/src/xdisp.c
index 0281370008c..1cc3e2eaadb 100644
--- a/src/xdisp.c
+++ b/src/xdisp.c
@@ -17976,12 +17976,13 @@ find_row_edges (struct it *it, struct glyph_row *row,
      lines' rows is implemented for bidi-reordered rows.  */
 
   /* ROW->minpos is the value of min_pos, the minimal buffer position
-     we have in ROW.  */
-  if (min_pos <= ZV)
+     we have in ROW, or ROW->start.pos if that is smaller.  */
+  if (min_pos <= ZV && min_pos < row->start.pos.charpos)
     SET_TEXT_POS (row->minpos, min_pos, min_bpos);
   else
-    /* We didn't find _any_ valid buffer positions in any of the
-       glyphs, so we must trust the iterator's computed positions.  */
+    /* We didn't find buffer positions smaller than ROW->start, or
+       didn't find _any_ valid buffer positions in any of the glyphs,
+       so we must trust the iterator's computed positions.  */
       row->minpos = row->start.pos;
   if (max_pos <= 0)
     {
-- 
2.39.5