Alfredo Braunstein wrote: > Angus Leeming wrote: > >> On Friday 26 March 2004 7:05 pm, Andre Poenitz wrote: >>> On Thu, Mar 25, 2004 at 04:20:18PM +0000, Angus Leeming wrote: >>> > LyX is crashing when iterating over insets. Note the two added >>> > lines, below. That looks very, very wrong :-( >>> >>> This seems to be solvable. Attached a 'makepatch.sh' style patch >>> that replaces Buffer::inset_iterator by some small wrapper around >>> DocumentIterator. >>> >>> [Alfredo: Is this close to what you proposed for PosIterator?] >>> >>> Seem to work. >>> >>> Could you please verify this and apply if sound?
Ok, your testcase works fine with Andre's patch and this implementation of forwardInset. I've reimplemented forwardPar as well which was severely fsckd up. I'll apply both shortly if there are no objections. Alfredo
Index: dociterator.C =================================================================== RCS file: /usr/local/lyx/cvsroot/lyx-devel/src/dociterator.C,v retrieving revision 1.7 diff -u -p -u -r1.7 dociterator.C --- dociterator.C 25 Mar 2004 09:16:15 -0000 1.7 +++ dociterator.C 27 Mar 2004 12:11:32 -0000 @@ -232,6 +232,37 @@ InsetBase * DocumentIterator::innerInset } +void DocumentIterator::forwardPar() +{ + while (depth()) { + size_t old_depth = depth(); + idx_type old_idx = idx(); + par_type old_par = par(); + + forwardPos(); + + if (depth() > old_depth) + break; + if (depth() == old_depth && + (old_idx != idx() || old_par != par())) + break; + } +} + + +void DocumentIterator::forwardInset() +{ + while (depth()) { + size_t old_depth = depth(); + + forwardPos(); + + if (depth() > old_depth) + break; + } +} + + void DocumentIterator::forwardPos() { CursorSlice & top = back(); @@ -296,9 +327,9 @@ void DocumentIterator::forwardPos() void DocumentIterator::forwardChar() { - forwardPos(); - while (size() != 0 && pos() == lastpos()) - forwardPos(); + do { + forwardPos(); + } while (size() != 0 && pos() == lastpos()); } @@ -306,62 +337,6 @@ void DocumentIterator::backwardChar() { lyxerr << "not implemented" << endl; BOOST_ASSERT(false); -} - - -void DocumentIterator::forwardPar() -{ - CursorSlice & top = back(); - lyxerr << "XXX " << *this << endl; - - // move into an inset to the right if possible - InsetBase * n = 0; - if (top.pos() != lastpos()) { - // this is impossible for pos() == size() - if (inMathed()) { - n = (top.cell().begin() + top.pos())->nucleus(); - } else { - if (paragraph().isInset(top.pos())) - n = paragraph().getInset(top.pos()); - } - } - - if (n && n->isActive()) { - lyxerr << "... descend" << endl; - push_back(CursorSlice(*n)); - return; - } - - // otherwise move on one cell back if possible - if (top.pos() < lastpos()) { - lyxerr << "... next pos" << endl; - ++top.pos(); - return; - } - - // otherwise move on one cell back if possible - if (top.par() < lastpar()) { - lyxerr << "... next par" << endl; - ++top.par(); - top.pos() = 0; - return; - } - - // otherwise try to move on one cell if possible - while (top.idx() < top.lastidx()) { - lyxerr << "... next idx" - << " was: " << top.idx() << " max: " << top.lastidx() << endl; - ++top.idx(); - top.par() = 0; - top.pos() = 0; - return; - } - - // otherwise leave inset an jump over inset as a whole - pop_back(); - // 'top' is invalid now... - if (size()) - ++back().pos(); }