}
+bool positionable(MathCursor::cursor_type const & cursor,
+ MathCursor::cursor_type const & anchor)
+{
+ // avoid deeper nested insets when selecting
+ if (cursor.size() > anchor.size())
+ return false;
+
+ // anchor might be deeper, should have same path then
+ for (MathCursor::cursor_type::size_type i = 0; i < cursor.size(); ++i)
+ if (cursor[i].par_ != anchor[i].par_)
+ return false;
+
+ // position should be ok.
+ return true;
+}
+
void MathCursor::setPos(int x, int y)
{
MathIterator et = iend(formula()->par().nucleus());
for ( ; it != et; ++it) {
//lyxerr << "*it: " << *it << " *et: " << *et << "\n";
- if (selection_) {
- // avoid deeper nested insets when selecting
- if (it.cursor().size() > Anchor_.size())
- continue;
- // anchor might be deeper!
- if (it.cursor().size() == Anchor_.size())
- if (it.par() != Anchor_.back().par_)
- continue;
- //if (it.par() != Anchor_[it.cursor().size()].par_)
- // continue;
- }
+ // avoid invalid nesting hen selecting
+ if (selection_ && !positionable(it.cursor(), Anchor_))
+ continue;
//lyxerr << it.position() << endl;
int xo = it.position().xpos();
int yo = it.position().ypos();
}
}
- return goUp() || selection_;
+ cursor_type save = Cursor_;
+ if (goUpDown(true))
+ return true;
+ Cursor_ = save;
+ return selection_;
}
}
}
- return goDown() || selection_;
+ cursor_type save = Cursor_;
+ if (goUpDown(false))
+ return true;
+ Cursor_ = save;
+ return selection_;
}
}
-bool MathCursor::goUp()
+bool MathCursor::goUpDown(bool up)
{
- // first ask the inset if it knows better then we
- if (par()->idxUp(idx(), pos())) {
- //lyxerr << "ask cell\n";
- int xlow, xhigh, ylow, yhigh;
- xarray().boundingBox(xlow, xhigh, ylow, yhigh);
- bruteFind(xlow, xhigh, ylow, yhigh);
- return true;
- }
-
- // if not, apply brute force.
- //lyxerr << "brute force\n";
- return
- bruteFind(
- formula()->xlow(),
- formula()->xhigh(),
- formula()->ylow(),
- xarray().yo() - 4 - xarray().ascent()
- );
-}
+ int xo, yo;
+ getPos(xo, yo);
+ // try to find an inset that knows better then we
+ while (1) {
+ // we found a cell that think something "below" us.
+ if (up) {
+ if (par()->idxUp(idx(), pos()))
+ break;
+ } else {
+ if (par()->idxDown(idx(), pos()))
+ break;
+ }
-bool MathCursor::goDown()
-{
- // first ask the inset if it knows better then we
- if (par()->idxDown(idx(), pos())) {
- //lyxerr << "ask cell\n";
- int xlow, xhigh, ylow, yhigh;
- xarray().boundingBox(xlow, xhigh, ylow, yhigh);
- bruteFind(xlow, xhigh, ylow, yhigh);
- return true;
+ if (!popLeft()) {
+ // have reached hull
+ return
+ bruteFind(xo, yo,
+ formula()->xlow(),
+ formula()->xhigh(),
+ up ? formula()->ylow() : yo + 4,
+ up ? yo - 4 : formula()->yhigh()
+ );
+ }
}
-
- // if not, apply brute force.
- //lyxerr << "brute force\n";
- return
- bruteFind(
- formula()->xlow(),
- formula()->xhigh(),
- xarray().yo() + 4 + xarray().descent(),
- formula()->yhigh()
- );
+ int xlow, xhigh, ylow, yhigh;
+ xarray().boundingBox(xlow, xhigh, ylow, yhigh);
+ bruteFind(xo, yo, xlow, xhigh, ylow, yhigh);
+ return true;
}
-bool MathCursor::bruteFind(int xlow, int xhigh, int ylow, int yhigh)
+bool MathCursor::bruteFind(int x, int y, int xlow, int xhigh, int ylow, int yhigh)
{
- int x;
- int y;
- getPos(x, y);
//lyxerr << "looking at range: "
// << "[" << xlow << "..." << xhigh << "]"
// << " x [" << ylow << "..." << yhigh << "]"