+ if (pos() == lastpos())
+ return false;
+ ++pos();
+ return true;
+}
+
+
+CursorSlice LCursor::anchor() const
+{
+ BOOST_ASSERT(anchor_.depth() >= depth());
+ CursorSlice normal = anchor_[depth() - 1];
+ if (depth() < anchor_.depth() && top() <= normal) {
+ // anchor is behind cursor -> move anchor behind the inset
+ ++normal.pos();
+ }
+ return normal;
+}
+
+
+CursorSlice LCursor::selBegin() const
+{
+ if (!selection())
+ return top();
+ return anchor() < top() ? anchor() : top();
+}
+
+
+CursorSlice LCursor::selEnd() const
+{
+ if (!selection())
+ return top();
+ return anchor() > top() ? anchor() : top();
+}
+
+
+DocIterator LCursor::selectionBegin() const
+{
+ if (!selection())
+ return *this;
+ return anchor() < top() ? anchor_ : *this;
+}
+
+
+DocIterator LCursor::selectionEnd() const
+{
+ if (!selection())
+ return *this;
+ return anchor() > top() ? anchor_ : *this;
+}
+
+
+void LCursor::setSelection()
+{
+ selection() = true;
+ // A selection with no contents is not a selection
+#ifdef WITH_WARNINGS
+#warning doesnt look ok
+#endif
+ if (pit() == anchor().pit() && pos() == anchor().pos())
+ selection() = false;
+}
+
+
+void LCursor::setSelection(DocIterator const & where, size_t n)
+{
+ setCursor(where);
+ selection() = true;
+ anchor_ = where;
+ pos() += n;
+ // Open all collapsed insets
+ for (int i = depth() - 1; i >= 0; --i)
+ operator[](i).inset().setStatus(*this, InsetBase::Open);
+}
+
+
+void LCursor::clearSelection()
+{
+ selection() = false;
+ mark() = false;
+ resetAnchor();
+ bv().unsetXSel();
+}
+
+
+int & LCursor::x_target()
+{
+ return x_target_;
+}
+
+
+int LCursor::x_target() const
+{
+ return x_target_;
+}
+
+
+void LCursor::clearTargetX()
+{
+ x_target_ = -1;
+}
+
+
+
+void LCursor::info(std::ostream & os) const
+{
+ for (int i = 1, n = depth(); i < n; ++i) {
+ operator[](i).inset().infoize(os);
+ os << " ";
+ }
+ if (pos() != 0)
+ prevInset()->infoize2(os);
+ // overwite old message
+ os << " ";
+}
+
+
+void LCursor::selHandle(bool sel)
+{
+ //lyxerr << "LCursor::selHandle" << endl;
+ if (sel == selection())
+ return;
+
+ resetAnchor();
+ selection() = sel;
+}
+
+
+std::ostream & operator<<(std::ostream & os, LCursor const & cur)
+{
+ os << "\n cursor: | anchor:\n";
+ for (size_t i = 0, n = cur.depth(); i != n; ++i) {
+ os << " " << cur[i] << " | ";
+ if (i < cur.anchor_.depth())
+ os << cur.anchor_[i];
+ else
+ os << "-------------------------------";
+ os << "\n";
+ }
+ for (size_t i = cur.depth(), n = cur.anchor_.depth(); i < n; ++i) {
+ os << "------------------------------- | " << cur.anchor_[i] << "\n";
+ }
+ os << " selection: " << cur.selection_
+ << " x_target: " << cur.x_target_ << endl;
+ return os;
+}
+
+
+
+
+///////////////////////////////////////////////////////////////////
+//
+// The part below is the non-integrated rest of the original math
+// cursor. This should be either generalized for texted or moved
+// back to mathed (in most cases to MathNestInset).
+//
+///////////////////////////////////////////////////////////////////
+
+#include "mathed/math_charinset.h"
+#include "mathed/math_factory.h"
+#include "mathed/math_gridinset.h"
+#include "mathed/math_macroarg.h"
+#include "mathed/math_mathmlstream.h"
+#include "mathed/math_scriptinset.h"
+#include "mathed/math_support.h"
+#include "mathed/math_unknowninset.h"
+
+//#define FILEDEBUG 1
+
+
+bool LCursor::isInside(InsetBase const * p)
+{
+ for (size_t i = 0; i != depth(); ++i)
+ if (&operator[](i).inset() == p)