]> git.lyx.org Git - features.git/commitdiff
Fix bug 5762: http://bugzilla.lyx.org/show_bug.cgi?id=5762.
authorVincent van Ravesteijn <vfr@lyx.org>
Thu, 26 Feb 2009 21:01:35 +0000 (21:01 +0000)
committerVincent van Ravesteijn <vfr@lyx.org>
Thu, 26 Feb 2009 21:01:35 +0000 (21:01 +0000)
[visual cursor] Crash when moving left in table in an RTL document

Avoid negative positions.

git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@28626 a592a061-630c-0410-9148-cb99ea01b6c8

src/Cursor.cpp

index 1cfd32dd88994dd0a4df5adf4e69387d800f7c08..7939116c1a29075bb9ec6246df05cf8157d4ee0e 100644 (file)
@@ -834,11 +834,13 @@ void Cursor::posVisToRowExtremity(bool left)
                        // this non-separator-but-last-position-in-row is an inset, then
                        // we *do* want to stay to the left of it anyway: this is the 
                        // "boundary" which we simulate at insets.
+                       // Another exception is when row.endpos() is 0.
                        
                        bool right_of_pos = false; // do we want to be to the right of pos?
 
                        // as explained above, if at last pos in row, stay to the right
-                       if ((pos() == row.endpos() - 1) && !par.isInset(pos()))
+                       if (row.endpos() > 0 && pos() == row.endpos() - 1
+                                 && !par.isInset(pos()))
                                right_of_pos = true;
 
                        // Now we know if we want to be to the left or to the right of pos,
@@ -859,7 +861,10 @@ void Cursor::posVisToRowExtremity(bool left)
                if (!par.isRTL(buf.params()) && row.endpos() == lastpos())
                        pos() = lastpos();
                else {
-                       pos() = bidi.vis2log(row.endpos() - 1);
+                       if (row.endpos() > 0)
+                               pos() = bidi.vis2log(row.endpos() - 1);
+                       else
+                               pos() = 0;
 
                        // Moving to the rightmost position in the row, the cursor should
                        // normally be placed to the *right* of the rightmost position.
@@ -884,11 +889,14 @@ void Cursor::posVisToRowExtremity(bool left)
                        // this non-separator-but-last-position-in-row is an inset, then
                        // we *do* want to stay to the right of it anyway: this is the 
                        // "boundary" which we simulate at insets.
+                       // Another exception is when row.endpos() is 0.
                        
                        bool left_of_pos = false; // do we want to be to the left of pos?
 
-                       // as explained above, if at last pos in row, stay to the left
-                       if ((pos() == row.endpos() - 1) && !par.isInset(pos()))
+                       // as explained above, if at last pos in row, stay to the left,
+                       // unless the last position is the same as the first.
+                       if (row.endpos() > 0 && pos() == row.endpos() - 1 
+                                 && !par.isInset(pos()))
                                left_of_pos = true;
 
                        // Now we know if we want to be to the left or to the right of pos,