When pressing math with the mouse, move to the closest edge (#9748)

Unless it has some dialog that we want to activate.
This commit is contained in:
Guillaume Munch 2017-02-18 22:23:14 +01:00
parent bac8a95871
commit 63be456c8d
3 changed files with 27 additions and 8 deletions

View File

@ -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

View File

@ -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:

View File

@ -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();