This the same concept as the previous post for CursorSlices. A/
DocIterator.cpp | 83 ++++++-------------------------------------------------- DocIterator.h | 33 ++++++---------------- 2 files changed, 18 insertions(+), 98 deletions(-)
Index: DocIterator.cpp =================================================================== --- DocIterator.cpp (revision 19615) +++ DocIterator.cpp (working copy) @@ -58,7 +58,7 @@ } -Inset * DocIterator::nextInset() +Inset * DocIterator::nextInset() const { BOOST_ASSERT(!empty()); if (pos() == lastpos()) @@ -73,7 +73,7 @@ } -Inset * DocIterator::prevInset() +Inset * DocIterator::prevInset() const { BOOST_ASSERT(!empty()); if (pos() == 0) @@ -90,23 +90,6 @@ } -Inset const * DocIterator::prevInset() const -{ - BOOST_ASSERT(!empty()); - if (pos() == 0) - return 0; - if (inMathed()) - if (cell().empty()) - // FIXME: this should not happen but it does. - // See bug 3189 - // http://bugzilla.lyx.org/show_bug.cgi?id=3189 - return 0; - else - return prevAtom().nucleus(); - return paragraph().isInset(pos() - 1) ? paragraph().getInset(pos() - 1) : 0; -} - - Inset * DocIterator::realInset() const { BOOST_ASSERT(inTexted()); @@ -119,7 +102,7 @@ } -MathAtom const & DocIterator::prevAtom() const +MathAtom & DocIterator::prevAtom() const { BOOST_ASSERT(!empty()); BOOST_ASSERT(pos() > 0); @@ -127,46 +110,23 @@ } -MathAtom & DocIterator::prevAtom() +MathAtom & DocIterator::nextAtom() const { BOOST_ASSERT(!empty()); - BOOST_ASSERT(pos() > 0); - return cell()[pos() - 1]; -} - - -MathAtom const & DocIterator::nextAtom() const -{ - BOOST_ASSERT(!empty()); //lyxerr << "lastpos: " << lastpos() << " next atom:\n" << *this << endl; BOOST_ASSERT(pos() < lastpos()); return cell()[pos()]; } -MathAtom & DocIterator::nextAtom() +Text * DocIterator::text() const { BOOST_ASSERT(!empty()); - //lyxerr << "lastpos: " << lastpos() << " next atom:\n" << *this << endl; - BOOST_ASSERT(pos() < lastpos()); - return cell()[pos()]; -} - - -Text * DocIterator::text() -{ - BOOST_ASSERT(!empty()); return top().text(); } -Text const * DocIterator::text() const -{ - BOOST_ASSERT(!empty()); - return top().text(); -} - -Paragraph & DocIterator::paragraph() +Paragraph & DocIterator::paragraph() const { if (!inTexted()) lyxerr << *this << endl; @@ -175,15 +135,8 @@ } -Paragraph const & DocIterator::paragraph() const +Paragraph & DocIterator::innerParagraph() const { - BOOST_ASSERT(inTexted()); - return top().paragraph(); -} - - -Paragraph const & DocIterator::innerParagraph() const -{ BOOST_ASSERT(!empty()); // go up until first non-0 text is hit // (innermost text is 0 in mathed) @@ -249,34 +202,16 @@ } -MathData const & DocIterator::cell() const +MathData & DocIterator::cell() const { // BOOST_ASSERT(inMathed()); return top().cell(); } -MathData & DocIterator::cell() +Text * DocIterator::innerText() const { -// BOOST_ASSERT(inMathed()); - return top().cell(); -} - - -Text * DocIterator::innerText() -{ BOOST_ASSERT(!empty()); - // Go up until first non-0 text is hit - // (innermost text is 0 in mathed) - for (int i = depth() - 1; i >= 0; --i) - if (slices_[i].text()) - return slices_[i].text(); - return 0; -} - -Text const * DocIterator::innerText() const -{ - BOOST_ASSERT(!empty()); // go up until first non-0 text is hit // (innermost text is 0 in mathed) for (int i = depth() - 1; i >= 0; --i) Index: DocIterator.h =================================================================== --- DocIterator.h (revision 19615) +++ DocIterator.h (working copy) @@ -115,11 +115,9 @@ /// return the last column of the top grid col_type lastcol() const { return ncols() - 1; } /// the inset just behind the cursor - Inset * nextInset(); + Inset * nextInset() const; /// the inset just in front of the cursor - Inset * prevInset(); - /// the inset just in front of the cursor - Inset const * prevInset() const; + Inset * prevInset() const; /// bool boundary() const { return boundary_; } /// @@ -138,42 +136,29 @@ // math-specific part // /// return the mathed cell this cursor is in - MathData const & cell() const; - /// return the mathed cell this cursor is in - MathData & cell(); + MathData & cell() const; /// the mathatom left of the cursor - MathAtom const & prevAtom() const; - /// the mathatom left of the cursor - MathAtom & prevAtom(); + MathAtom & prevAtom() const; /// the mathatom right of the cursor - MathAtom const & nextAtom() const; - /// the mathatom right of the cursor - MathAtom & nextAtom(); + MathAtom & nextAtom() const; - // // text-specific part // - /// the paragraph we're in - Paragraph & paragraph(); /// the paragraph we're in in text mode. /// \warning only works within text! - Paragraph const & paragraph() const; + Paragraph & paragraph() const; /// the paragraph we're in in any case. /// This method will give the containing paragraph if /// in not in text mode (ex: in mathed). - Paragraph const & innerParagraph() const; + Paragraph & innerParagraph() const; /// - Text * text(); - /// - Text const * text() const; + Text * text() const; /// the containing inset or the cell, respectively Inset * realInset() const; /// Inset * innerInsetOfType(int code) const; /// - Text * innerText(); - /// - Text const * innerText() const; + Text * innerText() const; // // elementary moving