From 359aef92f87169ce2683e287bb24bc3d5f46a190 Mon Sep 17 00:00:00 2001 From: Georg Baum Date: Sun, 11 Oct 2015 14:21:45 +0200 Subject: [PATCH] Fix cursor movement for large logos (#9628) Previously, if one clicked onto a large non-editable inset like the new LyX logo inset, the cursor was always positioned in front of the inset, even if the click was almost at the back edge. Now the cursor is positioned at the correct edge. I tested this also with RTL contents, where from means right and back means left, but the inset anchor position anchor point is still at the left, and the right edge is dim.wid pixels to the right of it. --- src/TextMetrics.cpp | 21 +++++++++++++++++++-- 1 file changed, 19 insertions(+), 2 deletions(-) diff --git a/src/TextMetrics.cpp b/src/TextMetrics.cpp index 902c62d7e3..7831c13e04 100644 --- a/src/TextMetrics.cpp +++ b/src/TextMetrics.cpp @@ -1323,11 +1323,28 @@ Inset * TextMetrics::editXY(Cursor & cur, int x, int y, cur.setTargetX(x); // Try to descend recursively inside the inset. - inset = inset->editXY(cur, x, yy); + Inset * edited = inset->editXY(cur, x, yy); + if (edited == inset && cur.pos() == it->pos) { + // non-editable inset, set cursor after the inset if x is + // nearer to that position (bug 9628) + ParagraphMetrics const & pm = par_metrics_[pit]; + Dimension const & dim = pm.insetDimension(inset); + Point p = bv_->coordCache().getInsets().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(); + } + } if (cur.top().text() == text_) cur.setCurrentFont(); - return inset; + return edited; } -- 2.39.2