From: Vincent van Ravesteijn Date: Thu, 26 Feb 2009 21:01:35 +0000 (+0000) Subject: Fix bug 5762: http://bugzilla.lyx.org/show_bug.cgi?id=5762. X-Git-Tag: 2.0.0~7141 X-Git-Url: https://git.lyx.org/gitweb/?a=commitdiff_plain;h=28cb30831353d5e51f50462d2c77c51c2f29c545;p=lyx.git Fix bug 5762: http://bugzilla.lyx.org/show_bug.cgi?id=5762. [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 --- diff --git a/src/Cursor.cpp b/src/Cursor.cpp index 1cfd32dd88..7939116c1a 100644 --- a/src/Cursor.cpp +++ b/src/Cursor.cpp @@ -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,