From 63be456c8d087ad3a43f20be351b36cc3b67b37a Mon Sep 17 00:00:00 2001 From: Guillaume Munch Date: Sat, 18 Feb 2017 22:23:14 +0100 Subject: [PATCH] When pressing math with the mouse, move to the closest edge (#9748) Unless it has some dialog that we want to activate. --- src/Cursor.cpp | 16 ++++++++++++++++ src/Cursor.h | 6 ++++++ src/mathed/InsetMathNest.cpp | 13 +++++-------- 3 files changed, 27 insertions(+), 8 deletions(-) diff --git a/src/Cursor.cpp b/src/Cursor.cpp index 05389d9845..e694a13ddd 100644 --- a/src/Cursor.cpp +++ b/src/Cursor.cpp @@ -2435,4 +2435,20 @@ bool Cursor::confirmDeletion(bool const before) const } +void Cursor::moveToClosestEdge(int const x, bool const edit) +{ + if (Inset const * inset = nextInset()) { + // stay in front of insets for which we want to open the dialog + // (e.g. InsetMathSpace). + if (edit && (inset->hasSettings() || !inset->contextMenuName().empty())) + return; + CoordCache::Insets const & insetCache = bv().coordCache().getInsets(); + int const wid = insetCache.dim(inset).wid; + Point p = insetCache.xy(inset); + if (x > p.x_ + (wid + 1) / 2) + posForward(); + } +} + + } // namespace lyx diff --git a/src/Cursor.h b/src/Cursor.h index dbdd1569b8..1abc177ca4 100644 --- a/src/Cursor.h +++ b/src/Cursor.h @@ -399,6 +399,12 @@ public: /// one inset in the selection has confirmDeletion. bool confirmDeletion(bool before = false) const; + /// Determine if x falls to the left or to the side of the middle of the + /// inset, and advance the cursor to match this position. If edit is true, + /// keep the cursor in front of the inset if it matter for dialogs. + /// Note: it does not handle RTL text yet, and is only used in math for now. + void moveToClosestEdge(int x, bool edit = false); + public: //private: diff --git a/src/mathed/InsetMathNest.cpp b/src/mathed/InsetMathNest.cpp index ee0edd964f..0ba4bad38d 100644 --- a/src/mathed/InsetMathNest.cpp +++ b/src/mathed/InsetMathNest.cpp @@ -1581,6 +1581,10 @@ void InsetMathNest::lfunMousePress(Cursor & cur, FuncRequest & cmd) return; } } + + // set cursor after the inset if x is nearer to that position (bug 9748) + cur.moveToClosestEdge(cmd.x(), true); + bool do_selection = cmd.button() == mouse_button::button1 && cmd.modifier() == ShiftModifier; bv.mouseSetCursor(cur, do_selection); @@ -1626,14 +1630,7 @@ void InsetMathNest::lfunMouseMotion(Cursor & cur, FuncRequest & cmd) } // set cursor after the inset if x is nearer to that position (bug 9748) - if (Inset const * inset = cur.nextInset()) { - CoordCache::Insets const & insetCache = - cur.bv().coordCache().getInsets(); - int const wid = insetCache.dim(inset).wid; - Point p = insetCache.xy(inset); - if (cmd.x() > p.x_ + (wid + 1) / 2) - cur.posForward(); - } + cur.moveToClosestEdge(cmd.x()); CursorSlice old = bvcur.top();