]> git.lyx.org Git - lyx.git/blobdiff - src/cursor.C
fix crash when collapsing ert with cursor inside
[lyx.git] / src / cursor.C
index ac9bd45ab8ec4aff76e5812afd04d4b9dc4f3a03..f0fb6577c928862d079112b58bd26220424de418 100644 (file)
@@ -123,8 +123,6 @@ namespace {
        {
                BOOST_ASSERT(!cursor.empty());
                CursorSlice bottom = cursor[0];
-               LyXText * text = bottom.text();
-               BOOST_ASSERT(text);
 
                DocIterator it = doc_iterator_begin(bottom.inset());
                DocIterator const et = doc_iterator_end(bottom.inset());
@@ -509,13 +507,24 @@ std::ostream & operator<<(std::ostream & os, LCursor const & cur)
 
 bool LCursor::isInside(InsetBase const * p)
 {
-       for (unsigned i = 0; i < depth(); ++i)
+       for (size_t i = 0; i < depth(); ++i)
                if (&operator[](i).inset() == p)
                        return true;
        return false;
 }
 
 
+void LCursor::leaveInset(InsetBase const & inset)
+{
+       for (size_t i = 0; i != depth(); ++i) {
+               if (&operator[](i).inset() == &inset) {
+                       resize(i);
+                       return;
+               }
+       }
+}
+
+
 bool LCursor::openable(MathAtom const & t) const
 {
        if (!t->isActive())
@@ -1169,7 +1178,7 @@ void LCursor::fixIfBroken()
                               << ". Trying to correct this."  << endl;
                        newdepth = copy.depth() - 1;
                }
-               copy.pop();     
+               copy.pop();
        }
        // shrink cursor to a size where everything is valid, possibly
        // leaving insets
@@ -1178,3 +1187,4 @@ void LCursor::fixIfBroken()
                lyxerr << "correcting cursor to level " << depth() << endl;
        }
 }
+