* 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.
*/
#include "insets/Inset.h"
#include "mathed/InsetMath.h"
-#include "mathed/MathData.h"
+#include "mathed/MathMacro.h"
+#include "support/ExceptionMessage.h"
+#include "support/gettext.h"
#include "support/lassert.h"
#include <ostream>
CursorSlice::CursorSlice(Inset & p)
: inset_(&p), idx_(0), pit_(0), pos_(0)
{
- LASSERT(inset_, /**/);
+ LBUFERR(inset_);
}
pos_type CursorSlice::lastpos() const
{
- LASSERT(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());
}
CursorSlice::row_type CursorSlice::row() const
{
- LASSERT(asInsetMath(), /**/);
- return asInsetMath()->row(idx_);
+ LASSERT(inset_, return 0);
+ return inset_->row(idx_);
}
CursorSlice::col_type CursorSlice::col() const
{
- LASSERT(asInsetMath(), /**/);
- return asInsetMath()->col(idx_);
+ LASSERT(inset_, return 0);
+ return inset_->col(idx_);
}
// otherwise move on one cell
//lyxerr << "... next idx" << endl;
- LASSERT(idx_ < nargs(), /**/);
+ LASSERT(idx_ < nargs(), return);
++idx_;
pit_ = 0;
void CursorSlice::forwardIdx()
{
- LASSERT(idx_ < nargs(), /**/);
+ LASSERT(idx_ < nargs(), return);
++idx_;
pit_ = 0;
return;
}
- LASSERT(false, /**/);
+ LATTEST(false);
}
-bool CursorSlice::at_end() const
+bool CursorSlice::at_cell_end() const
{
- return idx_ == lastidx() && pit_ == lastpit() && pos_ == lastpos();
+ return pit_ == lastpit() && pos_ == lastpos();
+}
+
+
+bool CursorSlice::at_cell_begin() const
+{
+ return pit_ == 0 && pos_ == 0;
+}
+
+
+bool CursorSlice::at_end() const
+{
+ return idx_ == lastidx() && at_cell_end();
}
bool CursorSlice::at_begin() const
{
- return idx_ == 0 && pit_ == 0 && pos_ == 0;
+ return idx_ == 0 && at_cell_begin();
}
if (p.inset_ != q.inset_) {
LYXERR0("can't compare cursor and anchor in different insets\n"
<< "p: " << p << '\n' << "q: " << q);
- LASSERT(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_;