X-Git-Url: https://git.lyx.org/gitweb/?a=blobdiff_plain;f=src%2FCursorSlice.cpp;h=0ff99882ec0ceedd1e8f60ca435fc562dcf2893b;hb=8db4a8dd4663cdd6a3cf67777ea2538a380d0dd2;hp=1b4b8ca862402c9df4f52c4db30cc402ac4e7197;hpb=c3363f110df7441596dfee27cc7e813c139fda74;p=lyx.git diff --git a/src/CursorSlice.cpp b/src/CursorSlice.cpp index 1b4b8ca862..0ff99882ec 100644 --- a/src/CursorSlice.cpp +++ b/src/CursorSlice.cpp @@ -25,12 +25,11 @@ #include "mathed/MathData.h" #include -#include +using std::endl; -namespace lyx { -using std::endl; +namespace lyx { CursorSlice::CursorSlice() @@ -45,34 +44,6 @@ CursorSlice::CursorSlice(Inset & p) } -CursorSlice::CursorSlice(CursorSlice const & cs) -{ - operator=(cs); -} - - -CursorSlice & CursorSlice::operator=(CursorSlice const & cs) -{ - inset_ = cs.inset_; - idx_ = cs.idx_; - pit_ = cs.pit_; - pos_ = cs.pos_; - return *this; -} - - -void CursorSlice::invalidate() -{ - inset_ = 0; -} - - -bool CursorSlice::isValid() const -{ - return inset_ != 0; -} - - MathData & CursorSlice::cell() const { return inset_->asInsetMath()->cell(idx_); @@ -120,6 +91,71 @@ CursorSlice::col_type CursorSlice::col() const } +void CursorSlice::forwardPos() +{ + // move on one position if possible + if (pos() < lastpos()) { + //lyxerr << "... next pos" << endl; + ++pos(); + return; + } + + // otherwise move on one paragraph if possible + if (pit() < lastpit()) { + //lyxerr << "... next par" << endl; + ++pit(); + pos() = 0; + return; + } + + // otherwise try to move on one cell if possible + if (idx() < lastidx()) { + //lyxerr << "... next idx" << endl; + ++idx(); + pit() = 0; + pos() = 0; + return; + } + BOOST_ASSERT(false); +} + + +void CursorSlice::backwardPos() +{ + if (pos() != 0) { + --pos(); + return; + } + + if (pit() != 0) { + --pit(); + pos() = lastpos(); + return; + } + + if (idx() != 0) { + --idx(); + pit() = lastpit(); + pos() = lastpos(); + return; + } + + BOOST_ASSERT(false); +} + + +bool CursorSlice::at_end() const +{ + return idx() == lastidx() && pit() == lastpit() && pos() == lastpos(); +} + + +bool CursorSlice::at_begin() const +{ + return idx() == 0 && pit() == 0 && pos() == 0; +} + + bool operator==(CursorSlice const & p, CursorSlice const & q) { return &p.inset() == &q.inset()