X-Git-Url: https://git.lyx.org/gitweb/?a=blobdiff_plain;f=src%2FCursorSlice.cpp;h=105df9685b5f68267bb239b14c6214da4339496a;hb=ffff88e7fcd46afaa3b1823e9fcdc4aad4e2114b;hp=e7ef90e8f37c3040e32aead6e0e595344f7a1d84;hpb=9c55af4a223ce4db29d643251109e245665344bd;p=features.git diff --git a/src/CursorSlice.cpp b/src/CursorSlice.cpp index e7ef90e8f3..105df9685b 100644 --- a/src/CursorSlice.cpp +++ b/src/CursorSlice.cpp @@ -17,16 +17,14 @@ #include "Text.h" #include "Paragraph.h" +#include "ParagraphList.h" #include "support/debug.h" -#include "insets/Inset.h" - #include "mathed/InsetMath.h" -#include "mathed/MathMacro.h" +#include "mathed/InsetMathMacro.h" +#include "mathed/MathData.h" -#include "support/ExceptionMessage.h" -#include "support/gettext.h" #include "support/lassert.h" #include @@ -37,7 +35,7 @@ namespace lyx { CursorSlice::CursorSlice() - : inset_(0), idx_(0), pit_(0), pos_(0) + : inset_(nullptr), idx_(0), pit_(0), pos_(0) {} @@ -65,7 +63,7 @@ pos_type CursorSlice::lastpos() const 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()); } @@ -78,21 +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: 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_->col(idx_); } -CursorSlice::col_type CursorSlice::col() const +void CursorSlice::setPitPos(pit_type pit, pos_type pos) { - // 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(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); + } }