X-Git-Url: https://git.lyx.org/gitweb/?a=blobdiff_plain;f=src%2Fiterators.C;h=6ae3a237e28863fb74ab08c2d387b5af57b83c9c;hb=98c966c64594611e469313314abd1e59524adb4a;hp=e94479dd049e60c8ed05430734ffe06bfaaa8e4c;hpb=0233b6753d5a7ef67263c3111411be04765c629b;p=lyx.git diff --git a/src/iterators.C b/src/iterators.C index e94479dd04..6ae3a237e2 100644 --- a/src/iterators.C +++ b/src/iterators.C @@ -2,28 +2,33 @@ #include "iterators.h" -ParIterator & ParIterator::operator++() +ParIterator & ParIterator::operator++() { while (!positions.empty()) { - ParPosition & p = positions.back(); + ParPosition & p = positions.top(); // Does the current inset contain more "cells" ? if (p.index >= 0) { ++p.index; Paragraph * par = (*p.it)->getFirstParagraph(p.index); if (par) { - positions.push_back(ParPosition(par)); + positions.push(ParPosition(par)); return *this; } ++p.it; - } + } else + // The following line is needed because the value of + // p.it may be invalid if inset was added/removed to + // the paragraph pointed by the iterator + p.it = p.par->inset_iterator_begin(); // Try to find the next inset that contains paragraphs - for ( ; p.it != p.par->inset_iterator_end(); ++p.it) { + Paragraph::inset_iterator end = p.par->inset_iterator_end(); + for (; p.it != end; ++p.it) { Paragraph * par = (*p.it)->getFirstParagraph(0); if (par) { p.index = 0; - positions.push_back(ParPosition(par)); + positions.push(ParPosition(par)); return *this; } } @@ -33,7 +38,7 @@ ParIterator & ParIterator::operator++() return *this; } - positions.pop_back(); + positions.pop(); } return *this; }