changeset 111115:5445dbf4ccc1

Fix support for R2L lines. Tested with reordered text. xdisp.c (mouse_face_from_string_pos): Fix support for R2L lines.
author Eli Zaretskii <eliz@gnu.org>
date Sat, 23 Oct 2010 16:41:50 +0200
parents 674f04c442a5
children b52e94e0cf53
files src/ChangeLog src/xdisp.c
diffstat 2 files changed, 61 insertions(+), 36 deletions(-) [+]
line wrap: on
line diff
--- a/src/ChangeLog	Sat Oct 23 14:58:12 2010 +0200
+++ b/src/ChangeLog	Sat Oct 23 16:41:50 2010 +0200
@@ -5,6 +5,7 @@
 	our early if no row in the window belongs to the highlighted
 	string.  Always back up after exiting the second loop.
 	Fix off-by-one error when testing against ENDPOS.
+	Fix support for R2L lines.
 
 2010-10-16  Eli Zaretskii  <eliz@gnu.org>
 
--- a/src/xdisp.c	Sat Oct 23 14:58:12 2010 +0200
+++ b/src/xdisp.c	Sat Oct 23 16:41:50 2010 +0200
@@ -24425,35 +24425,48 @@
   int found = 0;
 
   /* Find the glyph row with at least one position in the range
-     [STARTPOS..ENDPOS], and the leftmost glyph in that row whose
+     [STARTPOS..ENDPOS], and the first glyph in that row whose
      position belongs to that range.  */
   for (r = MATRIX_FIRST_TEXT_ROW (w->current_matrix);
        r->enabled_p && r->y < yb;
        ++r)
     {
-      g = r->glyphs[TEXT_AREA];
-      e = g + r->used[TEXT_AREA];
-      for (gx = r->x; g < e; gx += g->pixel_width, ++g)
-	if (EQ (g->object, object)
-	    && startpos <= g->charpos && g->charpos <= endpos)
-	  {
-	    dpyinfo->mouse_face_beg_row = r - w->current_matrix->rows;
-	    dpyinfo->mouse_face_beg_y = r->y;
-	    if (!r->reversed_p)
+      if (!r->reversed_p)
+	{
+	  g = r->glyphs[TEXT_AREA];
+	  e = g + r->used[TEXT_AREA];
+	  for (gx = r->x; g < e; gx += g->pixel_width, ++g)
+	    if (EQ (g->object, object)
+		&& startpos <= g->charpos && g->charpos <= endpos)
 	      {
+		dpyinfo->mouse_face_beg_row = r - w->current_matrix->rows;
+		dpyinfo->mouse_face_beg_y = r->y;
 		dpyinfo->mouse_face_beg_col = g - r->glyphs[TEXT_AREA];
 		dpyinfo->mouse_face_beg_x = gx;
+		found = 1;
+		break;
 	      }
-	    else
+	}
+      else
+	{
+	  struct glyph *g1;
+
+	  e = r->glyphs[TEXT_AREA];
+	  g = e + r->used[TEXT_AREA];
+	  for ( ; g > e; --g)
+	    if (EQ ((g-1)->object, object)
+		&& startpos <= (g-1)->charpos && (g-1)->charpos <= endpos)
 	      {
-		/* R2L rows want BEG and END swapped, see
-		   show_mouse_face.  */
-		dpyinfo->mouse_face_end_col = g - r->glyphs[TEXT_AREA];
-		dpyinfo->mouse_face_end_x = gx;
+		dpyinfo->mouse_face_beg_row = r - w->current_matrix->rows;
+		dpyinfo->mouse_face_beg_y = r->y;
+		dpyinfo->mouse_face_beg_col = g - r->glyphs[TEXT_AREA];
+		for (gx = r->x, g1 = r->glyphs[TEXT_AREA]; g1 < g; ++g1)
+		  gx += g1->pixel_width;
+		dpyinfo->mouse_face_beg_x = gx;
+		found = 1;
+		break;
 	      }
-	    found = 1;
-	    break;
-	  }
+	}
       if (found)
 	break;
     }
@@ -24486,25 +24499,36 @@
   dpyinfo->mouse_face_end_row = r - w->current_matrix->rows;
   dpyinfo->mouse_face_end_y = r->y;
 
-  /* Compute and set the end column.  */
-  g = r->glyphs[TEXT_AREA];
-  e = g + r->used[TEXT_AREA];
-  for ( ; e > g; --e)
-    if (EQ ((e-1)->object, object)
-	&& startpos <= (e-1)->charpos && (e-1)->charpos <= endpos)
-      break;
+  /* Compute and set the end column and the end column's horizontal
+     pixel coordinate.  */
   if (!r->reversed_p)
-    dpyinfo->mouse_face_end_col = e - g;
-  else
-    dpyinfo->mouse_face_beg_col = e - g;
-
-  /* Compute and set the end column's horizontal pixel coordinate.  */
-  for (gx = r->x; g < e; ++g)
-    gx += g->pixel_width;
-  if (!r->reversed_p)
-    dpyinfo->mouse_face_end_x = gx;
-  else
-    dpyinfo->mouse_face_beg_x = gx;
+    {
+      g = r->glyphs[TEXT_AREA];
+      e = g + r->used[TEXT_AREA];
+      for ( ; e > g; --e)
+	if (EQ ((e-1)->object, object)
+	    && startpos <= (e-1)->charpos && (e-1)->charpos <= endpos)
+	  break;
+      dpyinfo->mouse_face_end_col = e - g;
+
+      for (gx = r->x; g < e; ++g)
+	gx += g->pixel_width;
+      dpyinfo->mouse_face_end_x = gx;
+    }
+  else
+    {
+      e = r->glyphs[TEXT_AREA];
+      g = e + r->used[TEXT_AREA];
+      for (gx = r->x ; e < g; ++e)
+	{
+	  if (EQ (e->object, object)
+	      && startpos <= e->charpos && e->charpos <= endpos)
+	    break;
+	  gx += e->pixel_width;
+	}
+      dpyinfo->mouse_face_end_col = e - r->glyphs[TEXT_AREA];
+      dpyinfo->mouse_face_end_x = gx;
+    }
 }
 
 /* See if position X, Y is within a hot-spot of an image.  */