X-Git-Url: https://git.lyx.org/gitweb/?a=blobdiff_plain;f=src%2Fcursor.C;h=a9fd17e47b3a70f975964267243c0d236f251b4f;hb=530749439472bddf13d9f4ee74ee6184ef76e3f9;hp=6aeaec8884d0d8f47d0cf33045fe79c611b77a8e;hpb=aa491cdb98f6e99827324c41fede08bb789d67c6;p=lyx.git diff --git a/src/cursor.C b/src/cursor.C index 6aeaec8884..a9fd17e47b 100644 --- a/src/cursor.C +++ b/src/cursor.C @@ -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()); @@ -199,6 +197,7 @@ void LCursor::dispatch(FuncRequest const & cmd0) if (empty()) return; + fixIfBroken(); FuncRequest cmd = cmd0; LCursor safe = *this; @@ -1139,3 +1138,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; + } +}