}
// if not, apply brute force.
- int x0;
- int y0;
- getPos(x0, y0);
- std::vector<MathCursorPos> save = Cursor_;
- y0 -= xarray().ascent();
- for (int y = y0 - 4; y > formula()->upperY(); y -= 4) {
- setPos(x0, y);
- if (save != Cursor_ && xarray().yo() < y0)
- return true;
- }
- Cursor_ = save;
- return false;
+ return
+ bruteUpDown(formula()->upperY() + 24, xarray().yo() - 4 - xarray().ascent());
}
return true;
}
- // does the inset know
-
// if not, apply brute force.
+ return
+ bruteUpDown(xarray().yo() + 4 + xarray().descent(), formula()->lowerY());
+}
+
+
+bool MathCursor::bruteUpDown(int ylow, int yhigh)
+{
+ //lyxerr << "looking at range: " << ylow << " " << yhigh << "\n";
int x0;
int y0;
getPos(x0, y0);
std::vector<MathCursorPos> save = Cursor_;
- y0 += xarray().descent();
- for (int y = y0 + 4; y < formula()->lowerY(); y += 4) {
+ std::vector<MathCursorPos> best;
+ double best_dist = 1e10; // large enough
+ bool found = false;
+ for (int y = ylow; y < yhigh; y += 4) {
setPos(x0, y);
- if (save != Cursor_ && xarray().yo() > y0)
- return true;
+ int x1;
+ int y1;
+ getPos(x1, y1);
+ if (save != Cursor_ && y1 > ylow && y1 < yhigh) {
+ found = true;
+ double d = (x0 - x1) * (x0 - x1) + (y0 - y1) * (y0 - y1);
+ if (d < best_dist) {
+ best_dist = d;
+ best = Cursor_;
+ }
+ }
}
+
+ if (found) {
+ Cursor_ = best;
+ return true;
+ }
+
Cursor_ = save;
return false;
}
class MathCursor {
public:
/// short of anything else reasonable
- typedef MathInset::size_type size_type;
+ typedef MathInset::size_type size_type;
/// type for cursor positions within a cell
- typedef MathInset::pos_type pos_type;
+ typedef MathInset::pos_type pos_type;
/// type for cell indices
- typedef MathInset::idx_type idx_type;
+ typedef MathInset::idx_type idx_type;
/// type for row numbers
- typedef MathInset::row_type row_type;
+ typedef MathInset::row_type row_type;
/// type for column numbers
- typedef MathInset::col_type col_type;
+ typedef MathInset::col_type col_type;
+ /// how to store a cursor
+ typedef std::vector<MathCursorPos> cursor_type;
///
explicit MathCursor(InsetFormulaBase *, bool left);
MathCursorPos normalAnchor() const;
/// path of positions the cursor had to go if it were leving each inset
- std::vector<MathCursorPos> Cursor_;
+ cursor_type Cursor_;
/// path of positions the anchor had to go if it were leving each inset
- std::vector<MathCursorPos> Anchor_;
+ cursor_type Anchor_;
/// reference to the last item of the path
MathCursorPos & cursor();
bool goUp();
/// moves position somehow down
bool goDown();
+ /// moves position somehow down
+ bool bruteUpDown(int ylow, int yhigh);
///
string macroName() const;
bool MathGridInset::idxUp(idx_type & idx, pos_type & pos) const
{
+ return false;
+/*
if (idx < ncols())
return false;
int x = cellXOffset(idx) + xcell(idx).pos2x(pos);
idx -= ncols();
pos = xcell(idx).x2pos(x - cellXOffset(idx));
return true;
+*/
}
bool MathGridInset::idxDown(idx_type & idx, pos_type & pos) const
{
+ return false;
+/*
if (idx >= ncols() * (nrows() - 1))
return false;
int x = cellXOffset(idx) + xcell(idx).pos2x(pos);
idx += ncols();
pos = xcell(idx).x2pos(x - cellXOffset(idx));
return true;
+*/
}