X-Git-Url: https://git.lyx.org/gitweb/?a=blobdiff_plain;f=src%2FCursorSlice.cpp;h=105df9685b5f68267bb239b14c6214da4339496a;hb=a4d9315bc49445e4419b3b59fd238a13c5f7be31;hp=c4b1c72f80d803868a01b39e226e66cf1cba4841;hpb=f1cba8ff64b369792fd49f5ddf90e8126ab476ac;p=lyx.git diff --git a/src/CursorSlice.cpp b/src/CursorSlice.cpp index c4b1c72f80..105df9685b 100644 --- a/src/CursorSlice.cpp +++ b/src/CursorSlice.cpp @@ -17,12 +17,12 @@ #include "Text.h" #include "Paragraph.h" +#include "ParagraphList.h" #include "support/debug.h" -#include "insets/Inset.h" - #include "mathed/InsetMath.h" +#include "mathed/InsetMathMacro.h" #include "mathed/MathData.h" #include "support/lassert.h" @@ -35,14 +35,14 @@ namespace lyx { CursorSlice::CursorSlice() - : inset_(0), idx_(0), pit_(0), pos_(0) + : inset_(nullptr), idx_(0), pit_(0), pos_(0) {} CursorSlice::CursorSlice(Inset & p) : inset_(&p), idx_(0), pit_(0), pos_(0) { - LASSERT(inset_, /**/); + LBUFERR(inset_); } @@ -60,9 +60,11 @@ Paragraph & CursorSlice::paragraph() const pos_type CursorSlice::lastpos() const { - LASSERT(inset_, /**/); - return inset_->asInsetMath() ? cell().size() - : (text()->empty() ? 0 : paragraph().size()); + LBUFERR(inset_); + InsetMath const * math = inset_->asInsetMath(); + bool paramless_macro = math && math->asMacro() && !math->asMacro()->nargs(); + return math ? (paramless_macro ? 0 : cell().size()) + : (text()->empty() ? 0 : paragraph().size()); } @@ -74,17 +76,39 @@ pit_type CursorSlice::lastpit() const } -CursorSlice::row_type CursorSlice::row() const +row_type CursorSlice::row() const +{ + LASSERT(inset_, return 0); + return inset_->row(idx_); +} + + +col_type CursorSlice::col() const { - LASSERT(asInsetMath(), /**/); - return asInsetMath()->row(idx_); + LASSERT(inset_, return 0); + return inset_->col(idx_); } -CursorSlice::col_type CursorSlice::col() const +void CursorSlice::setPitPos(pit_type pit, pos_type pos) { - LASSERT(asInsetMath(), /**/); - return asInsetMath()->col(idx_); + LASSERT(pit != int(text()->paragraphs().size()), return); + pit_ = pit; + pos_ = pos; + + // Now some strict checking. None of these should happen, but + // we're scaredy-cats + if (pos < 0) { + LYXERR0("Don't like -1!"); + LATTEST(false); + } + + if (pos > paragraph().size()) { + LYXERR0("Don't like 1, pos: " << pos + << " size: " << paragraph().size() + << " par: " << pit); + LATTEST(false); + } } @@ -108,7 +132,7 @@ void CursorSlice::forwardPos() // otherwise move on one cell //lyxerr << "... next idx" << endl; - LASSERT(idx_ < nargs(), /**/); + LASSERT(idx_ < nargs(), return); ++idx_; pit_ = 0; @@ -118,7 +142,7 @@ void CursorSlice::forwardPos() void CursorSlice::forwardIdx() { - LASSERT(idx_ < nargs(), /**/); + LASSERT(idx_ < nargs(), return); ++idx_; pit_ = 0; @@ -146,19 +170,31 @@ void CursorSlice::backwardPos() return; } - LASSERT(false, /**/); + LATTEST(false); +} + + +bool CursorSlice::at_cell_end() const +{ + return pit_ == lastpit() && pos_ == lastpos(); +} + + +bool CursorSlice::at_cell_begin() const +{ + return pit_ == 0 && pos_ == 0; } -bool CursorSlice::at_end() const +bool CursorSlice::at_end() const { - return idx_ == lastidx() && pit_ == lastpit() && pos_ == lastpos(); + return idx_ == lastidx() && at_cell_end(); } bool CursorSlice::at_begin() const { - return idx_ == 0 && pit_ == 0 && pos_ == 0; + return idx_ == 0 && at_cell_begin(); } @@ -185,7 +221,8 @@ bool operator<(CursorSlice const & p, CursorSlice const & q) if (p.inset_ != q.inset_) { LYXERR0("can't compare cursor and anchor in different insets\n" << "p: " << p << '\n' << "q: " << q); - LASSERT(false, /**/); + // It should be safe to continue, just registering the error. + LASSERT(false, return false); } if (p.idx_ != q.idx_) return p.idx_ < q.idx_;