less crude MathXArray::x2pos for preciser cursor positioning using the mouse

git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@2325 a592a061-630c-0410-9148-cb99ea01b6c8
This commit is contained in:
André Pönitz 2001-07-24 16:39:55 +00:00
parent c1bd906202
commit c1364850c0
2 changed files with 13 additions and 3 deletions

View File

@ -10,6 +10,9 @@
* 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 <lasgouttes@lyx.org>
* formula.C (insetAllowed): allow insertion of label

View File

@ -97,8 +97,15 @@ 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 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;
}