]> git.lyx.org Git - features.git/commitdiff
better handling of up/down
authorAndré Pönitz <poenitz@gmx.net>
Fri, 30 Nov 2001 14:40:38 +0000 (14:40 +0000)
committerAndré Pönitz <poenitz@gmx.net>
Fri, 30 Nov 2001 14:40:38 +0000 (14:40 +0000)
git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@3123 a592a061-630c-0410-9148-cb99ea01b6c8

src/mathed/math_cursor.C
src/mathed/math_cursor.h
src/mathed/math_gridinset.C

index ce8795af0e32d551d8d8d0fe473c7994f8704545..04cca270d4448a6c6fcca2bf02c5ba3ccd4c0191 100644 (file)
@@ -1167,18 +1167,8 @@ bool MathCursor::goUp()
        }
 
        // 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());
 }
 
 
@@ -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<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;
 }
index dd305bb4fddc4136d3d3596c682eef1c255a5d25..bea6dcfce563a16f8564569eee1d3e991ec11979 100644 (file)
@@ -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<MathCursorPos> 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<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();
@@ -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;
index 9e5f84dc0cd1a4f384c2db3fde2da90533be7d14..4cdb775baea6e541aaea340e1ed3b8a3a02c1313 100644 (file)
@@ -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;
+*/
 }