]> git.lyx.org Git - features.git/commitdiff
more cursor up/down tuning...
authorAndré Pönitz <poenitz@gmx.net>
Tue, 11 Dec 2001 18:51:47 +0000 (18:51 +0000)
committerAndré Pönitz <poenitz@gmx.net>
Tue, 11 Dec 2001 18:51:47 +0000 (18:51 +0000)
git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@3194 a592a061-630c-0410-9148-cb99ea01b6c8

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

index 79176cae1d6b1765ec71aaf661faa543dc105b19..b6f5cc6f854563d69d7c610de6f7e0c8104f2ded 100644 (file)
@@ -316,6 +316,22 @@ void MathCursor::last()
 }
 
 
+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)
 {
@@ -327,17 +343,9 @@ 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();
@@ -557,7 +565,11 @@ bool MathCursor::up(bool sel)
                }
        }
 
-       return goUp() || selection_;
+       cursor_type save = Cursor_;
+       if (goUpDown(true))
+               return true;
+       Cursor_ = save;
+       return selection_;
 }
 
 
@@ -587,7 +599,11 @@ bool MathCursor::down(bool sel)
                }
        }
 
-       return goDown() || selection_;
+       cursor_type save = Cursor_;
+       if (goUpDown(false))
+               return true;
+       Cursor_ = save;
+       return selection_;
 }
 
 
@@ -1116,57 +1132,42 @@ MathCursorPos const & MathCursor::cursor() const
 }
 
 
-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 << "]"
index ec6ae8934b9bdca751ea773e70dadbcb3528173d..23c4f213088d8c28924f4b3ab2ce5cf8e34bc403 100644 (file)
@@ -242,12 +242,10 @@ private:
        bool idxLeft();
        /// moves cursor index one cell to the right
        bool idxRight();
-       /// moves position somehow up
-       bool goUp();
-       /// moves position somehow down
-       bool goDown();
+       /// moves position somehow up or down
+       bool goUpDown(bool up);
        /// moves position into box
-       bool bruteFind(int xlow, int xhigh, int ylow, int yhigh);
+       bool bruteFind(int xo, int yo, int xlow, int xhigh, int ylow, int yhigh);
 
        ///
        string macroName() const;
index ce2d94bee5782cdb510ee4fdd849ff2c74322062..6d06cf4a6e8bc8060cbf8df3960e40f1b3934e0a 100644 (file)
@@ -489,24 +489,18 @@ 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;
 }