X-Git-Url: https://git.lyx.org/gitweb/?a=blobdiff_plain;f=src%2FCursorSlice.cpp;h=c5be12f5000a6c6b6dc771036b5228609837a078;hb=79cf3f5ec1088e7de988e889247ec300d42fb70b;hp=09cf6241346ec097d9cfdd152d691a936a1f0f5c;hpb=0014ca7eee593b05959b99a0d9afb263f61ecf01;p=lyx.git diff --git a/src/CursorSlice.cpp b/src/CursorSlice.cpp index 09cf624134..c5be12f500 100644 --- a/src/CursorSlice.cpp +++ b/src/CursorSlice.cpp @@ -3,10 +3,10 @@ * This file is part of LyX, the document processor. * Licence details can be found in the file COPYING. * - * \author Lars Gullik Bjønnes + * \author Lars Gullik Bjønnes * \author Matthias Ettrich - * \author André Pönitz - * \author Jürgen Vigna + * \author André Pönitz + * \author Jürgen Vigna * * Full author contact details are available in file CREDITS. */ @@ -23,9 +23,11 @@ #include "insets/Inset.h" #include "mathed/InsetMath.h" -#include "mathed/MathData.h" +#include "mathed/InsetMathMacro.h" -#include +#include "support/ExceptionMessage.h" +#include "support/gettext.h" +#include "support/lassert.h" #include @@ -42,7 +44,7 @@ CursorSlice::CursorSlice() CursorSlice::CursorSlice(Inset & p) : inset_(&p), idx_(0), pit_(0), pos_(0) { - BOOST_ASSERT(inset_); + LBUFERR(inset_); } @@ -60,9 +62,11 @@ Paragraph & CursorSlice::paragraph() const pos_type CursorSlice::lastpos() const { - BOOST_ASSERT(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()); } @@ -76,15 +80,37 @@ pit_type CursorSlice::lastpit() const CursorSlice::row_type CursorSlice::row() const { - BOOST_ASSERT(asInsetMath()); - return asInsetMath()->row(idx_); + LASSERT(inset_, return 0); + return inset_->row(idx_); } CursorSlice::col_type CursorSlice::col() const { - BOOST_ASSERT(asInsetMath()); - return asInsetMath()->col(idx_); + LASSERT(inset_, return 0); + return inset_->col(idx_); +} + + +void CursorSlice::setPitPos(pit_type pit, pos_type pos) +{ + 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 +134,7 @@ void CursorSlice::forwardPos() // otherwise move on one cell //lyxerr << "... next idx" << endl; - BOOST_ASSERT(idx_ < nargs()); + LASSERT(idx_ < nargs(), return); ++idx_; pit_ = 0; @@ -118,7 +144,7 @@ void CursorSlice::forwardPos() void CursorSlice::forwardIdx() { - BOOST_ASSERT(idx_ < nargs()); + LASSERT(idx_ < nargs(), return); ++idx_; pit_ = 0; @@ -146,19 +172,31 @@ void CursorSlice::backwardPos() return; } - BOOST_ASSERT(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 +223,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); - BOOST_ASSERT(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_;