X-Git-Url: https://git.lyx.org/gitweb/?a=blobdiff_plain;f=src%2Fdociterator.C;h=4d93aa7a0177228266c36fc14b7445103b7ba74f;hb=35204f8f33d7400a5fefeffea533fb4cb4097211;hp=51ecd6406738bf716523a8a58eeff748f832bf4e;hpb=867998226431d6385234759302b2d16662271f91;p=lyx.git diff --git a/src/dociterator.C b/src/dociterator.C index 51ecd64067..4d93aa7a01 100644 --- a/src/dociterator.C +++ b/src/dociterator.C @@ -18,12 +18,17 @@ #include "lyxrow.h" #include "paragraph.h" -#include "mathed/math_data.h" -#include "mathed/math_inset.h" +#include "mathed/MathData.h" +#include "mathed/InsetMath.h" + +#include "insets/insettabular.h" #include #include + +namespace lyx { + using std::endl; @@ -90,6 +95,18 @@ InsetBase const * DocIterator::prevInset() const } +InsetBase * DocIterator::realInset() const +{ + BOOST_ASSERT(inTexted()); + // if we are in a tabular, we need the cell + if (inset().lyxCode() == InsetBase::TABULAR_CODE) { + InsetTabular & tabular = static_cast(inset()); + return tabular.cell(idx()).get(); + } + return &inset(); +} + + MathAtom const & DocIterator::prevAtom() const { BOOST_ASSERT(!empty()); @@ -167,13 +184,13 @@ Row const & DocIterator::textRow() const } -DocIterator::pit_type DocIterator::lastpit() const +pit_type DocIterator::lastpit() const { return inMathed() ? 0 : text()->paragraphs().size() - 1; } -DocIterator::pos_type DocIterator::lastpos() const +pos_type DocIterator::lastpos() const { return inMathed() ? cell().size() : paragraph().size(); } @@ -276,7 +293,7 @@ InsetBase * DocIterator::innerInsetOfType(int code) const } -void DocIterator::forwardPos() +void DocIterator::forwardPos(bool ignorecollapsed) { //this dog bites his tail if (empty()) { @@ -284,6 +301,15 @@ void DocIterator::forwardPos() return; } + // jump over collapsables if they are collapsed + // FIXME: the check for asInsetMath() shouldn't be necessary + // but math insets do not return a sensible editable() state yet. + if (ignorecollapsed && nextInset() && (!nextInset()->asInsetMath() + && nextInset()->editable() != InsetBase::HIGHLY_EDITABLE)) { + ++top().pos(); + return; + } + CursorSlice & tip = top(); //lyxerr << "XXX\n" << *this << endl; @@ -376,7 +402,11 @@ void DocIterator::forwardPosNoDescend() } //lyxerr << "... no next idx" << endl; - // otherwise we can't move on + // otherwise leave inset and jump over inset as a whole + pop_back(); + // 'top' is invalid now... + if (!empty()) + ++top().pos(); } @@ -384,10 +414,6 @@ void DocIterator::forwardPar() { forwardPos(); -#if 0 - DocIterator cmp(*this); -#endif - while (!empty() && (!inTexted() || pos() != 0)) { if (inTexted()) { pos_type const lastp = lastpos(); @@ -398,12 +424,6 @@ void DocIterator::forwardPar() } forwardPos(); } - -#if 0 - while (!cmp.empty() && (!cmp.inTexted() || cmp.pos() != 0)) - cmp.forwardPos(); - BOOST_ASSERT(cmp == *this); -#endif } @@ -418,8 +438,19 @@ void DocIterator::forwardChar() void DocIterator::forwardInset() { forwardPos(); - while (!empty() && (pos() == lastpos() || nextInset() == 0)) + + while (!empty() && !nextInset()) { + if (inTexted()) { + pos_type const lastp = lastpos(); + Paragraph const & par = paragraph(); + pos_type & pos = top().pos(); + while (pos < lastp && !par.isInset(pos)) + ++pos; + if (pos < lastp) + break; + } forwardPos(); + } } @@ -490,7 +521,7 @@ bool DocIterator::hasPart(DocIterator const & it) const } -void DocIterator::updateInsets(InsetBase * inset) +void DocIterator::updateInsets(InsetBase * inset) { // this function re-creates the cache of inset pointers. // code taken in part from StableDocIterator::asDocIterator. @@ -566,3 +597,5 @@ bool operator==(StableDocIterator const & dit1, StableDocIterator const & dit2) return dit1.data_ == dit2.data_; } + +} // namespace lyx