X-Git-Url: https://git.lyx.org/gitweb/?a=blobdiff_plain;f=src%2FCursorSlice.cpp;h=0ff99882ec0ceedd1e8f60ca435fc562dcf2893b;hb=8db4a8dd4663cdd6a3cf67777ea2538a380d0dd2;hp=840d4b1c32402768458bd3cd1977a37cbb084ca0;hpb=f630be890494c849981e4fb52ea4740506e92bed;p=lyx.git diff --git a/src/CursorSlice.cpp b/src/CursorSlice.cpp index 840d4b1c32..0ff99882ec 100644 --- a/src/CursorSlice.cpp +++ b/src/CursorSlice.cpp @@ -14,19 +14,22 @@ #include #include "CursorSlice.h" + #include "debug.h" -#include "LyXText.h" +#include "Text.h" #include "Paragraph.h" +#include "insets/Inset.h" + #include "mathed/InsetMath.h" -#include "mathed/MathArray.h" +#include "mathed/MathData.h" #include +using std::endl; -namespace lyx { -using std::endl; +namespace lyx { CursorSlice::CursorSlice() @@ -34,14 +37,14 @@ CursorSlice::CursorSlice() {} -CursorSlice::CursorSlice(InsetBase & p) +CursorSlice::CursorSlice(Inset & p) : inset_(&p), idx_(0), pit_(0), pos_(0) { BOOST_ASSERT(inset_); } -MathArray & CursorSlice::cell() const +MathData & CursorSlice::cell() const { return inset_->asInsetMath()->cell(idx_); } @@ -66,6 +69,14 @@ pos_type CursorSlice::lastpos() const } +pit_type CursorSlice::lastpit() const +{ + if (inset().inMathed()) + return 0; + return text()->paragraphs().size() - 1; +} + + CursorSlice::row_type CursorSlice::row() const { BOOST_ASSERT(asInsetMath()); @@ -80,9 +91,74 @@ 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_ + return &p.inset() == &q.inset() && p.idx() == q.idx() && p.pit() == q.pit() && p.pos() == q.pos(); @@ -91,7 +167,7 @@ bool operator==(CursorSlice const & p, CursorSlice const & q) bool operator!=(CursorSlice const & p, CursorSlice const & q) { - return p.inset_ != q.inset_ + return &p.inset() != &q.inset() || p.idx() != q.idx() || p.pit() != q.pit() || p.pos() != q.pos();