]> git.lyx.org Git - lyx.git/blobdiff - src/mathed/math_data.C
Fix to bug 2362: Deleting superscript also deletes subscript.
[lyx.git] / src / mathed / math_data.C
index 7c17e77e119db9685e31550b9baeefa196585cb5..790034aa1cf1abed796979d1e61e598add2c8c5a 100644 (file)
@@ -221,7 +221,7 @@ namespace {
 bool isInside(DocIterator const & it, MathArray const & ar,
        lyx::pos_type p1, lyx::pos_type p2)
 {
-       for (size_t i = 0; i != it.size(); ++i) {
+       for (size_t i = 0; i != it.depth(); ++i) {
                CursorSlice const & sl = it[i];
                if (sl.inset().inMathed() && &sl.cell() == &ar)
                        return p1 <= sl.pos() && sl.pos() < p2;
@@ -310,6 +310,7 @@ void MathArray::draw(PainterInfo & pi, int x, int y) const
                        }
                }
 #endif
+               theCoords.insets().add(at.nucleus(), x, y);
                at->drawSelection(pi, x, y);
                at->draw(pi, x, y);
                x += at->width();
@@ -374,14 +375,30 @@ MathArray::size_type MathArray::x2pos(int targetx, int glue) const
        const_iterator it = begin();
        int lastx = 0;
        int currx = 0;
+       // find first position after targetx
        for (; currx < targetx && it < end(); ++it) {
                lastx = currx;
                if ((*it)->getChar() == ' ')
                        currx += glue;
                currx += (*it)->width();
        }
-       if (abs(lastx - targetx) < abs(currx - targetx) && it != begin())
+
+       /** 
+        * If we are not at the beginning of the array, go to the left
+        * of the inset if one of the following two condition holds:
+        * - the current inset is editable (so that the cursor tip is
+        *   deeper than us): in this case, we want all intermediate
+        *   cursor slices to be before insets;
+        * - the mouse is closer to the left side of the inset than to
+        *   the right one.
+        * See bug 1918 for details.    
+        **/
+       if (it != begin()
+           && ((*boost::prior(it))->asNestInset()
+               || abs(lastx - targetx) < abs(currx - targetx))) {
                --it;
+       }
+
        return it - begin();
 }
 
@@ -410,19 +427,18 @@ int MathArray::dist(int x, int y) const
 
 void MathArray::setXY(int x, int y) const
 {
-       lyxerr << "setting position cache for MathArray " << this << std::endl;
-       theCoords.arrays_.add(this, x, y);
+       //lyxerr << "setting position cache for MathArray " << this << std::endl;
+       theCoords.arrays().add(this, x, y);
 }
 
 
 int MathArray::xo() const
 {
-       return theCoords.arrays_.x(this);
+       return theCoords.getArrays().x(this);
 }
 
 
 int MathArray::yo() const
 {
-       return theCoords.arrays_.y(this);
+       return theCoords.getArrays().y(this);
 }
-