X-Git-Url: https://git.lyx.org/gitweb/?a=blobdiff_plain;f=src%2FCursorSlice.cpp;h=c5be12f5000a6c6b6dc771036b5228609837a078;hb=b0a73c0dfdbfa0541f04d7ee2578c4cd272ef7b9;hp=0a600ab4bef0c2a77a8d929905df2c97accf68f6;hpb=1b1f8dd235ba8e168348cd23c824063f2595a0c5;p=lyx.git diff --git a/src/CursorSlice.cpp b/src/CursorSlice.cpp index 0a600ab4be..c5be12f500 100644 --- a/src/CursorSlice.cpp +++ b/src/CursorSlice.cpp @@ -23,7 +23,7 @@ #include "insets/Inset.h" #include "mathed/InsetMath.h" -#include "mathed/MathMacro.h" +#include "mathed/InsetMathMacro.h" #include "support/ExceptionMessage.h" #include "support/gettext.h" @@ -44,7 +44,7 @@ CursorSlice::CursorSlice() CursorSlice::CursorSlice(Inset & p) : inset_(&p), idx_(0), pit_(0), pos_(0) { - LBUFERR(inset_, _("Invalid initialization of CursorSlice!")); + LBUFERR(inset_); } @@ -62,10 +62,10 @@ Paragraph & CursorSlice::paragraph() const pos_type CursorSlice::lastpos() const { - LBUFERR(inset_, _("Cursor slice not properly initialized!")); + LBUFERR(inset_); InsetMath const * math = inset_->asInsetMath(); bool paramless_macro = math && math->asMacro() && !math->asMacro()->nargs(); - return math ? (paramless_macro ? 0 : cell().size()) + return math ? (paramless_macro ? 0 : cell().size()) : (text()->empty() ? 0 : paragraph().size()); } @@ -80,19 +80,37 @@ pit_type CursorSlice::lastpit() const CursorSlice::row_type CursorSlice::row() const { - // LASSERT: This should only ever be called from an InsetMath. - // Should we crash in release mode, though, or try to continue? - LASSERT(asInsetMath(), /**/); - return asInsetMath()->row(idx_); + LASSERT(inset_, return 0); + return inset_->row(idx_); } CursorSlice::col_type CursorSlice::col() const { - // LASSERT: This should only ever be called from an InsetMath. - // Should we crash in release mode, though, or try to continue? - LASSERT(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); + } } @@ -158,15 +176,27 @@ void CursorSlice::backwardPos() } -bool CursorSlice::at_end() const +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 { - 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(); }