]> git.lyx.org Git - features.git/commitdiff
bug 1918: Positioning cursor in mathinset with the mouse does not work correctly...
authorJean-Marc Lasgouttes <lasgouttes@lyx.org>
Fri, 24 Feb 2006 14:41:48 +0000 (14:41 +0000)
committerJean-Marc Lasgouttes <lasgouttes@lyx.org>
Fri, 24 Feb 2006 14:41:48 +0000 (14:41 +0000)
git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@13275 a592a061-630c-0410-9148-cb99ea01b6c8

src/mathed/ChangeLog
src/mathed/math_data.C

index b6431c8cab398440e6f2269dd385cbef10dedd36..989cd32ecf9da846a385b1799ae54fb3bdb8a1c4 100644 (file)
@@ -1,3 +1,9 @@
+2006-02-23  Jean-Marc Lasgouttes  <lasgouttes@lyx.org>
+
+       * math_data.C (x2pos): Place cursor correctly in the case of
+       MathNestInset; this avoids misplaced cursor (and subsequent crash)
+       when placing the mouse near a symbol inset.
+
 2006-02-17  Georg Baum  <Georg.Baum@post.rwth-aachen.de>
 
        * math_xymatrixinset.[Ch]: Readd
index 770f5048f5550e483db2e105402951cc9bb3adec..790034aa1cf1abed796979d1e61e598add2c8c5a 100644 (file)
@@ -375,6 +375,7 @@ 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() == ' ')
@@ -382,19 +383,20 @@ MathArray::size_type MathArray::x2pos(int targetx, int glue) const
                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;
-       // 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();