diff src/dispnew.c @ 110469:9fa0b071facc

Fix position calculation on mouse click within bidi-reordered composition.
author Kenichi Handa <handa@m17n.org>
date Wed, 22 Sep 2010 11:54:58 +0900
parents c2d849aa4021
children 66f6be9b4d43 ee58b36ab139
line wrap: on
line diff
--- a/src/dispnew.c	Tue Sep 21 20:45:10 2010 +0900
+++ b/src/dispnew.c	Wed Sep 22 11:54:58 2010 +0900
@@ -5420,6 +5420,22 @@
   if (STRINGP (it.string))
     string = it.string;
   *pos = it.current;
+  if (it.what == IT_COMPOSITION
+      && it.cmp_it.nchars > 1
+      && it.cmp_it.reversed_p)
+    {
+      /* The current display element is a grapheme cluster in a
+	 composition.  In that case, we need the position of the first
+	 character of the cluster.  But, as it.cmp_it.reversed_p is 1,
+	 it.current points to the last character of the cluster, thus
+	 we must move back to the first character of the same
+	 cluster.  */
+      CHARPOS (pos->pos) -= it.cmp_it.nchars - 1;
+      if (STRINGP (it.string))
+	BYTEPOS (pos->pos) = string_char_to_byte (string, CHARPOS (pos->pos));
+      else
+	BYTEPOS (pos->pos) = CHAR_TO_BYTE (CHARPOS (pos->pos));
+    }
 
 #ifdef HAVE_WINDOW_SYSTEM
   if (it.what == IT_IMAGE)