http://bugzilla.lyx.org/show_bug.cgi?id=4117
Index: Cursor.cpp =================================================================== --- Cursor.cpp (revision 19634) +++ Cursor.cpp (working copy) @@ -1482,12 +1482,14 @@ } -void Cursor::fixIfBroken() +bool Cursor::fixIfBroken() { if (DocIterator::fixIfBroken()) { clearSelection(); resetAnchor(); + return true; } + return false; } Index: Cursor.h =================================================================== --- Cursor.h (revision 19634) +++ Cursor.h (working copy) @@ -179,8 +179,9 @@ * Not using noUpdate() should never be wrong. */ void noUpdate(); - /// fix cursor in circumstances that should never happen - void fixIfBroken(); + /// fix cursor in circumstances that should never happen. + /// \retval true if a fix occured. + bool fixIfBroken(); /// output friend std::ostream & operator<<(std::ostream & os, Cursor const & cur); Index: mathed/InsetMathNest.cpp =================================================================== --- mathed/InsetMathNest.cpp (revision 19634) +++ mathed/InsetMathNest.cpp (working copy) @@ -568,8 +568,16 @@ // notify left insets and give them chance to set update flags lyx::notifyCursorLeaves(cur.beforeDispatchCursor(), cur); cur.fixIfBroken(); - } else - cur.undispatched(); + break; + } + + if (cur.fixIfBroken()) + // FIXME: Something bad happened. We pass the corrected Cursor + // instead of letting things go worse. + break; + + // We did not manage to move the cursor. + cur.undispatched(); break; }