This patch solves completely the issue of wrong display of the cursor
when it is right in front of an RTL set.
Normally when a cursor is in an inset in RTL mode, it's position is
being calculated in the following manner. the '|' is the cursor, the
[] is inset I, inside some outer inset A.
WORD [ins|et]
Lyx would inquire the X position of the cursor from the outer inset A,
when in LTR mode it'll return the position which is in the leftmost
part of the inset. Then it would inquire the relative position of the
cursor from inner inset I. it would add the results and display the
cursor in the result given by A+ the result given by B.
In RTL paragraphs, A returns the position in the rightmost edge of the
inset, and then it's adding to it the offset of the position given by
I. A gets the position of the rightmost edge of inset I by
substituting the inset's width from the position of the cursor before
the inset. It "fixes" the cursor's position if it recognizes that the
cursor is in the inset.
Now the problem is, that the code that recognizes whether or not the
cursor is in the inset is broken. It checks whether or not
par_[sl.pos()] contains inset, and it is true even if the cursor is
right before the inset and not in it! Like that:
WORD |[inset]
In that case the X coor "fix" would apply and the cursor would show up like that
WORD [inset]|
What I did is I added a better test for that. I tested whether or not
the cursor slice (which I don't understand EXACTLY what it means, it's
sort of pointer to a place in an inset) in the top of the cursor's
stack (ie, the cursor slice the cursor is in now) is equal to the
cursor slice we're getting as an input (which means the place we
should calculate the coordinate of). Only if it is not equal (ie, the
cursor is actually in the inset, and we need to calculate the
coordinates of a place outside the inset) we will apply the fix.
Dov - care to get another developer to agree and check it in?
Index: Text.cpp
===================================================================
--- Text.cpp	(revision 18497)
+++ Text.cpp	(working copy)
@@ -1696,8 +1696,21 @@
 	// edge (bidi!) -- MV
 	if (sl.pos() < par.size()) {
 		font = getFont(buffer, par, sl.pos());
+		//This fixes the cursor position in insets in RTL
+		//Paragraphs. I added an assertion to make sure we
+		//are IN some kind of inset. (so far it was applied even
+		//if the cursor was right before a paragraph, since the
+		//position of the cursor in the paragraph is the same
+		//regardless of whether or not the cursor is in the inset or not.
+		// We're testing now whether or not the cursor slice stored
+		// at the cursor, is the same cursor slice given by us.
+		// If it is, that means we're not in the inset which is at
+		// character sl.pos() in the pargraph, but we're right before
+		// it. Otherwise it means that the inset was pushed into the
+		// cursor's stack.
 		if (!boundary && font.isVisibleRightToLeft()
-		  && par.isInset(sl.pos()))
+		  && par.isInset(sl.pos())
+		  && (&bv.cursor().top())!=&sl)
 			x -= par.getInset(sl.pos())->width();
 	}
 	return int(x);

Reply via email to