X-Git-Url: https://git.lyx.org/gitweb/?a=blobdiff_plain;f=src%2Fdociterator.C;h=565a43f8945f26ca1f81e5ed50c36953cf378433;hb=37d42d45f3f4a5d3e916a080af50b37ae4a9d118;hp=81f465826baa3d697e9c56a20b9d554464a5a6d3;hpb=aa491cdb98f6e99827324c41fede08bb789d67c6;p=lyx.git diff --git a/src/dociterator.C b/src/dociterator.C index 81f465826b..565a43f894 100644 --- a/src/dociterator.C +++ b/src/dociterator.C @@ -20,8 +20,10 @@ #include "mathed/math_data.h" #include "mathed/math_inset.h" +#include "insets/insettabular.h" #include +#include using std::endl; @@ -29,12 +31,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 +91,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,6 +152,8 @@ LyXText const * DocIterator::text() const Paragraph & DocIterator::paragraph() { + if (!inTexted()) + lyxerr << *this << endl; BOOST_ASSERT(inTexted()); return top().paragraph(); } @@ -153,14 +169,14 @@ Paragraph const & DocIterator::paragraph() const Row & DocIterator::textRow() { BOOST_ASSERT(!paragraph().rows().empty()); - return paragraph().getRow(pos()); + return paragraph().getRow(pos(), boundary_); } Row const & DocIterator::textRow() const { BOOST_ASSERT(!paragraph().rows().empty()); - return paragraph().getRow(pos()); + return paragraph().getRow(pos(), boundary_); } @@ -273,7 +289,7 @@ InsetBase * DocIterator::innerInsetOfType(int code) const } -void DocIterator::forwardPos() +void DocIterator::forwardPos(bool ignorecollapsed) { //this dog bites his tail if (empty()) { @@ -281,6 +297,15 @@ void DocIterator::forwardPos() return; } + // jump over collapsables if they are collapsed + // FIXME: the check for asMathInset() shouldn't be necessary + // but math insets do not return a sensible editable() state yet. + if (ignorecollapsed && nextInset() && (!nextInset()->asMathInset() + && nextInset()->editable() != InsetBase::HIGHLY_EDITABLE)) { + ++top().pos(); + return; + } + CursorSlice & tip = top(); //lyxerr << "XXX\n" << *this << endl; @@ -341,11 +366,66 @@ void DocIterator::forwardPos() } +void DocIterator::forwardPosNoDescend() +{ + CursorSlice & tip = top(); + pos_type const lastp = lastpos(); + + // move on one position if possible + if (tip.pos() < lastp) { + //lyxerr << "... next pos" << endl; + ++tip.pos(); + return; + } + //lyxerr << "... no next pos" << endl; + + // otherwise move on one paragraph if possible + if (tip.pit() < lastpit()) { + //lyxerr << "... next par" << endl; + ++tip.pit(); + tip.pos() = 0; + return; + } + //lyxerr << "... no next pit" << endl; + + // otherwise try to move on one cell if possible + if (tip.idx() < lastidx()) { + //lyxerr << "... next idx" << endl; + ++tip.idx(); + tip.pit() = 0; + tip.pos() = 0; + return; + } + //lyxerr << "... no next idx" << endl; + + // otherwise we can't move on +} + + void DocIterator::forwardPar() { forwardPos(); - while (!empty() && (!inTexted() || pos() != 0)) + +#if 0 + DocIterator cmp(*this); +#endif + + while (!empty() && (!inTexted() || pos() != 0)) { + if (inTexted()) { + pos_type const lastp = lastpos(); + Paragraph const & par = paragraph(); + pos_type & pos = top().pos(); + while (pos < lastp && !par.isInset(pos)) + ++pos; + } forwardPos(); + } + +#if 0 + while (!cmp.empty() && (!cmp.inTexted() || cmp.pos() != 0)) + cmp.forwardPos(); + BOOST_ASSERT(cmp == *this); +#endif } @@ -432,6 +512,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) @@ -482,3 +581,10 @@ 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_; +} +