X-Git-Url: https://git.lyx.org/gitweb/?a=blobdiff_plain;f=src%2FCursorSlice.cpp;h=573ca9d4fe71b653bd2b3e1e02401c11171891b8;hb=8e1a869c45b0c1cb1ee1f3e85d51325224ec3eb4;hp=0e46c0781fc760ac8e8783fcd099011db555151f;hpb=d79225ae987164c59d92621f5f7de203d3179c4c;p=lyx.git diff --git a/src/CursorSlice.cpp b/src/CursorSlice.cpp index 0e46c0781f..573ca9d4fe 100644 --- a/src/CursorSlice.cpp +++ b/src/CursorSlice.cpp @@ -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(); }