diff --git a/src/mathed/ChangeLog b/src/mathed/ChangeLog index 1034326f4a..4df2d54075 100644 --- a/src/mathed/ChangeLog +++ b/src/mathed/ChangeLog @@ -9,6 +9,9 @@ * formulabase.C: fix memory leak * math_cursor.C: ^ now copies selection into new srriptinset + + * xarray.C: less crude MathXArray::x2pos for preciser cursor positioning + using the mouse 2001-07-22 Jean-Marc Lasgouttes diff --git a/src/mathed/xarray.C b/src/mathed/xarray.C index 0c19f1e8bc..269bfafefa 100644 --- a/src/mathed/xarray.C +++ b/src/mathed/xarray.C @@ -96,9 +96,16 @@ int MathXArray::pos2x(int targetpos) const int MathXArray::x2pos(int targetx) const { - int pos = 0; - for (int x = 0; x < targetx && pos < data_.size(); data_.next(pos)) - x += width(pos); + int pos = 0; + int lastx = 0; + int currx = 0; + while (currx < targetx && pos < data_.size()) { + lastx = currx; + currx += width(pos); + data_.next(pos); + } + if (abs(lastx - targetx) < abs(currx - targetx)) + data_.prev(pos); return pos; }