X-Git-Url: https://git.lyx.org/gitweb/?a=blobdiff_plain;f=src%2Fdociterator.C;h=bb72fb6c2d71c669dffc61b936fc3a36c9e4beaa;hb=0da3d53269a49c66b24615d24e20e441dcf7c07e;hp=b4fd5c2218892b23fc26617c782ea0f2451d8137;hpb=3c4af0ffbf73289dc6a1dd63fe9e90f41fa8b546;p=lyx.git diff --git a/src/dociterator.C b/src/dociterator.C index b4fd5c2218..bb72fb6c2d 100644 --- a/src/dociterator.C +++ b/src/dociterator.C @@ -15,13 +15,18 @@ #include "debug.h" #include "lyxtext.h" -#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; @@ -29,12 +34,12 @@ using std::endl; // We could be able to get rid of this if only every BufferView were // associated to a buffer on construction. DocIterator::DocIterator() - : inset_(0) + : boundary_(false), inset_(0) {} DocIterator::DocIterator(InsetBase & inset) - : inset_(&inset) + : boundary_(false), inset_(&inset) {} @@ -89,6 +94,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()); @@ -138,7 +155,7 @@ LyXText const * DocIterator::text() const Paragraph & DocIterator::paragraph() { - if (!inTexted()) + if (!inTexted()) lyxerr << *this << endl; BOOST_ASSERT(inTexted()); return top().paragraph(); @@ -152,27 +169,13 @@ Paragraph const & DocIterator::paragraph() const } -Row & DocIterator::textRow() -{ - BOOST_ASSERT(!paragraph().rows().empty()); - return paragraph().getRow(pos()); -} - - -Row const & DocIterator::textRow() const -{ - BOOST_ASSERT(!paragraph().rows().empty()); - return paragraph().getRow(pos()); -} - - -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(); } @@ -231,18 +234,6 @@ MathArray & DocIterator::cell() } -bool DocIterator::inMathed() const -{ - return !empty() && inset().inMathed(); -} - - -bool DocIterator::inTexted() const -{ - return !empty() && !inset().inMathed(); -} - - LyXText * DocIterator::innerText() { BOOST_ASSERT(!empty()); @@ -275,7 +266,7 @@ InsetBase * DocIterator::innerInsetOfType(int code) const } -void DocIterator::forwardPos() +void DocIterator::forwardPos(bool ignorecollapsed) { //this dog bites his tail if (empty()) { @@ -283,6 +274,16 @@ void DocIterator::forwardPos() return; } + InsetBase * const nextinset = nextInset(); + // 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; @@ -375,15 +376,31 @@ 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(); } void DocIterator::forwardPar() { forwardPos(); - while (!empty() && (!inTexted() || pos() != 0)) + + while (!empty() && (!inTexted() || pos() != 0)) { + if (inTexted()) { + pos_type const lastp = lastpos(); + Paragraph const & par = paragraph(); + pos_type & pos = top().pos(); + if (par.insetlist.empty()) + pos = lastp; + else + while (pos < lastp && !par.isInset(pos)) + ++pos; + } forwardPos(); + } } @@ -398,8 +415,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(); + } } @@ -470,6 +498,25 @@ bool DocIterator::hasPart(DocIterator const & it) const } +void DocIterator::updateInsets(InsetBase * inset) +{ + // this function re-creates the cache of inset pointers. + // code taken in part from StableDocIterator::asDocIterator. + //lyxerr << "converting:\n" << *this << endl; + DocIterator dit = DocIterator(*inset); + size_t const n = slices_.size(); + for (size_t i = 0 ; i < n; ++i) { + BOOST_ASSERT(inset); + dit.push_back(slices_[i]); + dit.top().inset_ = inset; + if (i + 1 != n) + inset = dit.nextInset(); + } + //lyxerr << "converted:\n" << *this << endl; + operator=(dit); +} + + std::ostream & operator<<(std::ostream & os, DocIterator const & dit) { for (size_t i = 0, n = dit.depth(); i != n; ++i) @@ -520,3 +567,12 @@ std::ostream & operator<<(std::ostream & os, StableDocIterator const & dit) os << " " << dit.data_[i] << "\n"; return os; } + + +bool operator==(StableDocIterator const & dit1, StableDocIterator const & dit2) +{ + return dit1.data_ == dit2.data_; +} + + +} // namespace lyx