Bo Peng wrote: >> > >> > I guess I need a more detailed description to reproduce it... >> >> <C-n>abcdefgh<C-m>1<M-f>w<Del><Del><Del><Del><Del><Del><Del><Del> >> >> Now do whatever is necessary in your environmet to switch back to the >> first window. > > I see. I need to remove enough chars to make pos > size in the old window.
I think something along the lines of the (completely untested) attached patch should be enough to get rid of the crashes. The destruction signaling machinery should not be needed anymore. Comments? A/
Index: CursorSlice.h =================================================================== --- CursorSlice.h (revision 18599) +++ 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: DocIterator.cpp =================================================================== --- DocIterator.cpp (revision 18599) +++ DocIterator.cpp (working copy) @@ -562,50 +562,41 @@ { 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 << "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 << "fixIfBroken(): idx fixed" << endl; + } else if (cs.pit() > cs.lastpit()) { + cs.pit() = cs.lastpit(); + cs.pos() = cs.lastpos(); + inset = 0; + fixed = true; + lyxerr << "fixIfBroken(): pit fixed" << endl; + } else if (cs.pos() > cs.lastpos()) { + cs.pos() = cs.lastpos(); + inset = 0; + fixed = true; + lyxerr << "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 18599) +++ 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());