master 69b186c1bc0: Fix move_it_* functions when moving across face with :box

Eli Zaretskii <[email protected]>
Newsgroups gmane.emacs.diffs
Message-ID <[email protected]>
branch: master
commit 69b186c1bc02785977a51854f19f940f1bce140d
Author: Eli Zaretskii <[email protected]>
Commit: Eli Zaretskii <[email protected]>

    Fix move_it_* functions when moving across face with :box
    
    * src/xdisp.c (move_it_in_display_line_to): Restore the
    it->start_of_box_run_p flag upon exiting, to the value it had
    before calling PRODUCE_GLYPHS for the last time, if the iterator
    didn't move to the next display element.  This prevents losing the
    flag in further calls to move_it_* functions.  (Bug#81570)
---
 src/xdisp.c | 18 ++++++++++++++++++
 1 file changed, 18 insertions(+)

diff --git a/src/xdisp.c b/src/xdisp.c
index f01ed8cb053..beb8d980ee3 100644
--- a/src/xdisp.c
+++ b/src/xdisp.c
@@ -10122,6 +10122,8 @@ move_it_in_display_line_to (struct it *it,
   bool saw_smaller_pos = prev_pos < to_charpos;
   bool line_number_pending = false;
   int this_line_subject_to_line_prefix = 0;
+  bool moved_to_next = false;
+  bool saved_start_of_box_run = it->start_of_box_run_p;
 
 #ifdef GLYPH_DEBUG
   /* atx_flag, atpos_flag and wrap_flag are assigned but never used;
@@ -10203,6 +10205,8 @@ move_it_in_display_line_to (struct it *it,
   if (IT_CHARPOS (*it) < CHARPOS (this_line_min_pos))
     SET_TEXT_POS (this_line_min_pos, IT_CHARPOS (*it), IT_BYTEPOS (*it));
 
+  saved_start_of_box_run = it->start_of_box_run_p;
+
   while (true)
     {
       int x, i, ascent = 0, descent = 0;
@@ -10331,7 +10335,11 @@ move_it_in_display_line_to (struct it *it,
 	 line.  */
       x = it->current_x;
 
+      /* We will record the start_of_box_run_p flag to restore it before
+         exiting if we never move from this glyph.  */
+      saved_start_of_box_run = it->start_of_box_run_p;
       PRODUCE_GLYPHS (it);
+      moved_to_next = false;
 
       if (it->area != TEXT_AREA)
 	{
@@ -10339,6 +10347,7 @@ move_it_in_display_line_to (struct it *it,
 	  if (it->method == GET_FROM_BUFFER)
 	    prev_pos = IT_CHARPOS (*it);
 	  set_iterator_to_next (it, true);
+	  moved_to_next = true;
 	  if (IT_CHARPOS (*it) < CHARPOS (this_line_min_pos))
 	    SET_TEXT_POS (this_line_min_pos,
 			  IT_CHARPOS (*it), IT_BYTEPOS (*it));
@@ -10517,6 +10526,7 @@ move_it_in_display_line_to (struct it *it,
 			  if (it->method == GET_FROM_BUFFER)
 			    prev_pos = IT_CHARPOS (*it);
 			  set_iterator_to_next (it, true);
+			  moved_to_next = true;
 			  if (IT_CHARPOS (*it) < CHARPOS (this_line_min_pos))
 			    SET_TEXT_POS (this_line_min_pos,
 					  IT_CHARPOS (*it), IT_BYTEPOS (*it));
@@ -10722,6 +10732,7 @@ move_it_in_display_line_to (struct it *it,
       /* The current display element has been consumed.  Advance to
 	 the next.  */
       set_iterator_to_next (it, true);
+      moved_to_next = true;
 
       /* If IT has just finished producing glyphs for the wrap prefix
 	 and is proceeding to the next method, there might not be
@@ -10852,6 +10863,13 @@ move_it_in_display_line_to (struct it *it,
   if (ppos_data)
     bidi_unshelve_cache (ppos_data, true);
 
+  /* Restore the start_of_box_run_p flag, if we haven't moved from the
+     position where it might have been set by get_next_display_element.
+     This is so the following iteration picks up this flag instead of
+     losing it (because PRODUCE_GLYPHS resets it).   */
+  if (!moved_to_next)
+    it->start_of_box_run_p = saved_start_of_box_run;
+
   /* Restore the iterator settings altered at the beginning of this
      function.  */
   it->glyph_row = saved_glyph_row;
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.