]> git.lyx.org Git - lyx.git/blobdiff - src/cursor.C
compilation fix
[lyx.git] / src / cursor.C
index 6aeaec8884d0d8f47d0cf33045fe79c611b77a8e..ac9bd45ab8ec4aff76e5812afd04d4b9dc4f3a03 100644 (file)
@@ -199,6 +199,7 @@ void LCursor::dispatch(FuncRequest const & cmd0)
        if (empty())
                return;
 
+       fixIfBroken();
        FuncRequest cmd = cmd0;
        LCursor safe = *this;
 
@@ -1139,3 +1140,41 @@ LyXFont LCursor::getFont() const
 
        return font;
 }
+
+
+void LCursor::fixIfBroken()
+{
+       // find out last good level
+       LCursor copy = *this;
+       size_t newdepth = depth();
+       while (!copy.empty()) {
+               if (copy.idx() > copy.lastidx()) {
+                       lyxerr << "wrong idx " << copy.idx()
+                              << ", max is " << copy.lastidx()
+                              << " at level " << copy.depth()
+                              << ". Trying to correct this."  << endl;
+                       newdepth = copy.depth() - 1;
+               }
+               else if (copy.pit() > copy.lastpit()) {
+                       lyxerr << "wrong pit " << copy.pit()
+                              << ", max is " << copy.lastpit()
+                              << " at level " << copy.depth()
+                              << ". Trying to correct this."  << endl;
+                       newdepth = copy.depth() - 1;
+               }
+               else if (copy.pos() > copy.lastpos()) {
+                       lyxerr << "wrong pos " << copy.pos()
+                              << ", max is " << copy.lastpos()
+                              << " at level " << copy.depth()
+                              << ". Trying to correct this."  << endl;
+                       newdepth = copy.depth() - 1;
+               }
+               copy.pop();     
+       }
+       // shrink cursor to a size where everything is valid, possibly
+       // leaving insets
+       while (depth() > newdepth) {
+               pop();
+               lyxerr << "correcting cursor to level " << depth() << endl;
+       }
+}