Stefan Schimanski wrote: > Some small questions: > Why don't you like comments?
? Be more specific. OTOH, I would have like some comment of yours when I asked for them a week ago... ;-) > Why do you need this complicated logic to set the inset to 0 in many > cases. Won't that end the loop anyway in the next round? Yes, but cutting off the DocIterator. > And, if the inset = 0 it's a broken cursor in any way, no? So take a > wrong idx, hence inset=0. In the next loop with inset()==inset will > not cut if off. I think it's wrong. Oh yes I forgot (too much time passed). This patch is intended to work *without* the signaling mechanism. So we should have no slice with inset == 0. So if the patch is to be applied without removing/deactivating the signaling mechanism, this slightly different version should do it, agreed? A/
Index: DocIterator.cpp =================================================================== --- DocIterator.cpp (revision 18720) +++ 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 || inset == 0) { + 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.h =================================================================== --- CursorSlice.h (revision 18720) +++ 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 Index: CursorSlice.cpp =================================================================== --- CursorSlice.cpp (revision 18720) +++ 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());