Jean-Marc Lasgouttes wrote: > Yes, the patch looks good, except that the messages are not very > informative (but as a usr I would be scared to see all these messages > in normal operation). And there is a very long line.
Fixed. Note that the scary messages are already there in svn. Please apply. A/ PS: should I prepare another patch with the removal of the destroyed signals etc?
Index: DocIterator.cpp =================================================================== --- DocIterator.cpp (revision 18704) +++ DocIterator.cpp (working copy) @@ -562,50 +562,48 @@ { bool fixed = false; - for (size_t i = slices_.size() - 1; i != 0; --i) - if (!slices_[i].isValid()) { - pop_back(); + Inset * inset = &slices_[0].inset(); + for (size_t i = 0, n = slices_.size(); i != n; ++i) { + CursorSlice & cs = slices_[i]; + if (&cs.inset() != inset) { + LYXERR(Debug::DEBUG) + << "fixIfBroken(): cursor chopped at " + << i << " because " << &cs.inset() + << " != " << inset << endl; + resize(i); + return true; + } else if (cs.idx() > cs.lastidx()) { + cs.idx() = cs.lastidx(); + cs.pit() = cs.lastpit(); + cs.pos() = cs.lastpos(); + inset = 0; fixed = true; + LYXERR(Debug::DEBUG) + << "fixIfBroken(): idx fixed" << endl; + } else if (cs.pit() > cs.lastpit()) { + cs.pit() = cs.lastpit(); + cs.pos() = cs.lastpos(); + inset = 0; + fixed = true; + LYXERR(Debug::DEBUG) + << "fixIfBroken(): pit fixed" << endl; + } else if (cs.pos() > cs.lastpos()) { + cs.pos() = cs.lastpos(); + inset = 0; + fixed = true; + LYXERR(Debug::DEBUG) + << "fixIfBroken(): pos fixed" << endl; + } else if (i != n - 1 && cs.pos() != cs.lastpos()) { + if (cs.inset().inMathed()) { + inset = (cs.cell().begin() + + cs.pos())->nucleus(); + } else { + inset = cs.paragraph().isInset(cs.pos()) ? + cs.paragraph().getInset(cs.pos()) : 0; + } } - - // The top level CursorSlice should always be valid. - BOOST_ASSERT(slices_[0].isValid()); - - if (idx() > lastidx()) { - lyxerr << "wrong idx " << idx() - << ", max is " << lastidx() - << " at level " << depth() - << ". Trying to correct this." << endl; - lyxerr << "old: " << *this << endl; - for (size_t i = idx(); i != lastidx(); --i) - pop_back(); - idx() = lastidx(); - pit() = lastpit(); - pos() = lastpos(); - fixed = true; } - else if (pit() > lastpit()) { - lyxerr << "wrong pit " << pit() - << ", max is " << lastpit() - << " at level " << depth() - << ". Trying to correct this." << endl; - lyxerr << "old: " << *this << endl; - pit() = lastpit(); - pos() = 0; - fixed = true; - } - else if (pos() > lastpos()) { - lyxerr << "wrong pos " << pos() - << ", max is " << lastpos() - << " at level " << depth() - << ". Trying to correct this." << endl; - lyxerr << "old: " << *this << endl; - pos() = lastpos(); - fixed = true; - } - if (fixed) { - lyxerr << "new: " << *this << endl; - } + return fixed; } Index: CursorSlice.cpp =================================================================== --- CursorSlice.cpp (revision 18704) +++ CursorSlice.cpp (working copy) @@ -112,6 +112,14 @@ } +pit_type CursorSlice::lastpit() const +{ + if (inset().inMathed()) + return 0; + return text()->paragraphs().size() - 1; +} + + CursorSlice::row_type CursorSlice::row() const { BOOST_ASSERT(asInsetMath()); Index: CursorSlice.h =================================================================== --- CursorSlice.h (revision 18704) +++ CursorSlice.h (working copy) @@ -81,6 +81,8 @@ pit_type pit() const { return pit_; } /// set the offset of the paragraph this cursor is in pit_type & pit() { return pit_; } + /// return the last paragraph offset this cursor is in + pit_type lastpit() const; /// increments the paragraph this cursor is in void incrementPar(); /// decrements the paragraph this cursor is in