From bafc40b857b5fc3341031365bf2f4cb3a4a13e45 Mon Sep 17 00:00:00 2001 From: Jean-Marc Lasgouttes Date: Thu, 6 Apr 2017 15:08:50 +0200 Subject: [PATCH] editXY: make cursor positionning correct over non editable inset Instead of using complicated (and wrong) code, it is better to use getPosNearX here. Also simplify the code by removing temporary variables. Fixes part of #10569. (cherry picked from commit 6a0c1c65734e0f25eb4fcbfb8926c98b77117c29) --- src/TextMetrics.cpp | 32 ++++++++++---------------------- 1 file changed, 10 insertions(+), 22 deletions(-) diff --git a/src/TextMetrics.cpp b/src/TextMetrics.cpp index 8f62eedcaa..0629c1e0cf 100644 --- a/src/TextMetrics.cpp +++ b/src/TextMetrics.cpp @@ -1369,23 +1369,19 @@ Inset * TextMetrics::editXY(Cursor & cur, int x, int y, } pit_type pit = getPitNearY(y); LASSERT(pit != -1, return 0); - - int yy = y; // is modified by getPitAndRowNearY - Row const & row = getPitAndRowNearY(yy, pit, assert_in_view, up); - + Row const & row = getPitAndRowNearY(y, pit, assert_in_view, up); cur.pit() = pit; // Do we cover an inset? - InsetList::InsetTable * it = checkInsetHit(pit, x, yy); + InsetList::InsetTable * it = checkInsetHit(pit, x, y); if (!it) { // No inset, set position in the text bool bound = false; // is modified by getPosNearX - int xx = x; // is modified by getPosNearX - cur.pos() = getPosNearX(row, xx, bound); + cur.pos() = getPosNearX(row, x, bound); cur.boundary(bound); cur.setCurrentFont(); - cur.setTargetX(xx); + cur.setTargetX(x); return 0; } @@ -1398,23 +1394,15 @@ Inset * TextMetrics::editXY(Cursor & cur, int x, int y, cur.setTargetX(x); // Try to descend recursively inside the inset. - Inset * edited = inset->editXY(cur, x, yy); + Inset * edited = inset->editXY(cur, x, y); if (edited == inset && cur.pos() == it->pos) { // non-editable inset, set cursor after the inset if x is // nearer to that position (bug 9628) - CoordCache::Insets const & insetCache = bv_->coordCache().getInsets(); - Dimension const & dim = insetCache.dim(inset); - Point p = insetCache.xy(inset); - bool const is_rtl = text_->isRTL(text_->getPar(pit)); - if (is_rtl) { - // "in front of" == "right of" - if (abs(p.x_ - x) < abs(p.x_ + dim.wid - x)) - cur.posForward(); - } else { - // "in front of" == "left of" - if (abs(p.x_ + dim.wid - x) < abs(p.x_ - x)) - cur.posForward(); - } + bool bound = false; // is modified by getPosNearX + cur.pos() = getPosNearX(row, x, bound); + cur.boundary(bound); + cur.setCurrentFont(); + cur.setTargetX(x); } if (cur.top().text() == text_) -- 2.39.5