]> git.lyx.org Git - lyx.git/blobdiff - src/mathed/math_data.C
Fix event loop to no longer eat CPU
[lyx.git] / src / mathed / math_data.C
index 7c17e77e119db9685e31550b9baeefa196585cb5..770f5048f5550e483db2e105402951cc9bb3adec 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();
@@ -380,8 +381,22 @@ MathArray::size_type MathArray::x2pos(int targetx, int glue) const
                        currx += glue;
                currx += (*it)->width();
        }
+
        if (abs(lastx - targetx) < abs(currx - targetx) && it != begin())
                --it;
+       // The below code guarantees that in this slice, the cursor will
+       // never be on the right edge of an inset after a mouse click.
+#ifdef WITH_WARNINGS
+#warning A better solution has to be found here!
+       // FIXME: this is too brute! The position left to an inset should
+       // be reachable with the mouse in general.
+#endif
+       if (it != begin()) {
+               --it;
+               if (it < end() && (*it)->getChar())
+                       ++it;
+       }
+
        return it - begin();
 }
 
@@ -410,19 +425,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);
 }
-