From: André Pönitz Date: Fri, 30 Nov 2001 14:40:38 +0000 (+0000) Subject: better handling of up/down X-Git-Tag: 1.6.10~20255 X-Git-Url: https://git.lyx.org/gitweb/?a=commitdiff_plain;h=5049e123be172b93bda8efc7e69a58d14dab2a97;p=features.git better handling of up/down git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@3123 a592a061-630c-0410-9148-cb99ea01b6c8 --- diff --git a/src/mathed/math_cursor.C b/src/mathed/math_cursor.C index ce8795af0e..04cca270d4 100644 --- a/src/mathed/math_cursor.C +++ b/src/mathed/math_cursor.C @@ -1167,18 +1167,8 @@ bool MathCursor::goUp() } // if not, apply brute force. - int x0; - int y0; - getPos(x0, y0); - std::vector 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()); } @@ -1198,19 +1188,42 @@ bool MathCursor::goDown() 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 save = Cursor_; - y0 += xarray().descent(); - for (int y = y0 + 4; y < formula()->lowerY(); y += 4) { + std::vector 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; } diff --git a/src/mathed/math_cursor.h b/src/mathed/math_cursor.h index dd305bb4fd..bea6dcfce5 100644 --- a/src/mathed/math_cursor.h +++ b/src/mathed/math_cursor.h @@ -58,15 +58,17 @@ bool operator<(MathCursorPos const &, MathCursorPos const &); 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 cursor_type; /// explicit MathCursor(InsetFormulaBase *, bool left); @@ -229,9 +231,9 @@ public: MathCursorPos normalAnchor() const; /// path of positions the cursor had to go if it were leving each inset - std::vector Cursor_; + cursor_type Cursor_; /// path of positions the anchor had to go if it were leving each inset - std::vector Anchor_; + cursor_type Anchor_; /// reference to the last item of the path MathCursorPos & cursor(); @@ -261,6 +263,8 @@ private: bool goUp(); /// moves position somehow down bool goDown(); + /// moves position somehow down + bool bruteUpDown(int ylow, int yhigh); /// string macroName() const; diff --git a/src/mathed/math_gridinset.C b/src/mathed/math_gridinset.C index 9e5f84dc0c..4cdb775bae 100644 --- a/src/mathed/math_gridinset.C +++ b/src/mathed/math_gridinset.C @@ -488,23 +488,29 @@ int MathGridInset::cellYOffset(idx_type idx) 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; +*/ }