+pit_type CursorSlice::lastpit() const
+{
+ if (inset_->inMathed())
+ return 0;
+ return text()->paragraphs().size() - 1;
+}
+
+
+row_type CursorSlice::row() const
+{
+ LASSERT(inset_, return 0);
+ return inset_->row(idx_);
+}
+
+
+col_type CursorSlice::col() const
+{
+ 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);
+ }
+}
+
+
+void CursorSlice::forwardPos()
+{
+ // move on one position if possible
+ if (pos_ < lastpos()) {
+ //lyxerr << "... next pos" << endl;
+ ++pos_;
+ return;
+ }
+
+ // otherwise move on one paragraph if possible
+ if (pit_ < lastpit()) {
+ //lyxerr << "... next par" << endl;
+ ++pit_;
+ pos_ = 0;
+ return;
+ }
+
+ // otherwise move on one cell
+ //lyxerr << "... next idx" << endl;
+
+ LASSERT(idx_ < nargs(), return);
+
+ ++idx_;
+ pit_ = 0;
+ pos_ = 0;
+}
+
+
+void CursorSlice::forwardIdx()
+{
+ LASSERT(idx_ < nargs(), return);
+
+ ++idx_;
+ pit_ = 0;
+ pos_ = 0;
+}
+
+
+void CursorSlice::backwardPos()
+{
+ if (pos_ != 0) {
+ --pos_;
+ return;
+ }
+
+ if (pit_ != 0) {
+ --pit_;
+ pos_ = lastpos();
+ return;
+ }
+
+ if (idx_ != 0) {
+ --idx_;
+ pit_ = lastpit();
+ pos_ = lastpos();
+ return;
+ }
+
+ LATTEST(false);
+}
+
+
+bool CursorSlice::at_cell_end() const
+{
+ return pit_ == lastpit() && pos_ == lastpos();
+}
+
+
+bool CursorSlice::at_cell_begin() const