From c1364850c09e7d5485b7e153e43bbfb2cfd82ee5 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Andr=C3=A9=20P=C3=B6nitz?= Date: Tue, 24 Jul 2001 16:39:55 +0000 Subject: [PATCH] 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 --- src/mathed/ChangeLog | 3 +++ src/mathed/xarray.C | 13 ++++++++++--- 2 files changed, 13 insertions(+), 3 deletions(-) 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; } -- 2.39.5