commit 6ea4a67863fcdd07872fa0a5aeaa187ae4e015e2
Author: Juergen Spitzmueller <sp...@lyx.org>
Date:   Thu Aug 24 09:56:09 2023 +0200

    Fix inset clicking problems on Mac (#12279, #12418, #12820)
    
    We now register the coordinates where the latest mouse press happens,
    and if that's on the inset button we are on when releasing,
    we toggle the inset.
    
    Thus, minimal unintentional mouse movements don't lead to the button not
    to respond.
    
    (cherry picked from commit effd65a586468321dcf0aeab34872d5607102477)
---
 src/Cursor.cpp                  |    8 ++++++++
 src/Cursor.h                    |    9 +++++++++
 src/Text3.cpp                   |    3 +++
 src/insets/Inset.cpp            |   10 +++++++---
 src/insets/InsetCollapsible.cpp |   10 +++++++---
 status.23x                      |    3 +++
 6 files changed, 37 insertions(+), 6 deletions(-)

diff --git a/src/Cursor.cpp b/src/Cursor.cpp
index bdfba61..0fff71d 100644
--- a/src/Cursor.cpp
+++ b/src/Cursor.cpp
@@ -176,6 +176,7 @@ LyXErr & operator<<(LyXErr & os, CursorData const & cur)
 Cursor::Cursor(BufferView & bv)
        : CursorData(&bv.buffer()), bv_(&bv),
          x_target_(-1), textTargetOffset_(0),
+         x_clickpos_(-1), y_clickpos_(-1), 
          beforeDispatchPosX_(0), beforeDispatchPosY_(0)
 {}
 
@@ -1093,6 +1094,13 @@ void Cursor::updateTextTargetOffset()
 }
 
 
+void Cursor::setClickPos(int x, int y)
+{
+       x_clickpos_ = x;
+       y_clickpos_ = y;
+}
+
+
 void Cursor::info(odocstream & os, bool devel_mode) const
 {
        for (int i = 1, n = depth(); i < n; ++i) {
diff --git a/src/Cursor.h b/src/Cursor.h
index 1da9dbd..4e59eb1 100644
--- a/src/Cursor.h
+++ b/src/Cursor.h
@@ -288,6 +288,12 @@ public:
        void setTargetX();
        /// clear targetX, i.e. set it to -1
        void clearTargetX();
+       /// return x position of latest mouse press or -1 if unset
+       int xClickPos() const { return x_clickpos_; }
+       /// return y position of latest mouse press or -1 if unset
+       int yClickPos() const { return y_clickpos_; }
+       /// register mouse press coordinates
+       void setClickPos(int x, int y);
        /// set offset to actual position - targetX
        void updateTextTargetOffset();
        /// distance between actual and targeted position during last up/down 
in text
@@ -442,6 +448,9 @@ private:
        int x_target_;
        /// if a x_target cannot be hit exactly in a text, put the difference 
here
        int textTargetOffset_;
+       /// Exact position of mouse click
+       int x_clickpos_;
+       int y_clickpos_;
        /// the start of the new born word
        DocIterator new_word_;
        /// position before dispatch started
diff --git a/src/Text3.cpp b/src/Text3.cpp
index 7ec8947..1d3e0fa 100644
--- a/src/Text3.cpp
+++ b/src/Text3.cpp
@@ -1780,6 +1780,7 @@ void Text::dispatch(Cursor & cur, FuncRequest & cmd)
                bvcur.setMark(false);
                switch (cmd.button()) {
                case mouse_button::button1:
+                       bvcur.setClickPos(cmd.x(), cmd.y());
                        if (!bvcur.selection())
                                // Set the cursor
                                bvcur.resetAnchor();
@@ -1868,6 +1869,8 @@ void Text::dispatch(Cursor & cur, FuncRequest & cmd)
        case LFUN_MOUSE_RELEASE:
                switch (cmd.button()) {
                case mouse_button::button1:
+                       // unregister last mouse press position 
+                       cur.bv().cursor().setClickPos(-1, -1); 
                        // Cursor was set at LFUN_MOUSE_PRESS or 
LFUN_MOUSE_MOTION time.
                        // If there is a new selection, update persistent 
selection;
                        // otherwise, single click does not clear persistent 
selection
diff --git a/src/insets/Inset.cpp b/src/insets/Inset.cpp
index 0935b06..b546a03 100644
--- a/src/insets/Inset.cpp
+++ b/src/insets/Inset.cpp
@@ -353,9 +353,13 @@ void Inset::doDispatch(Cursor & cur, FuncRequest &cmd)
 {
        switch (cmd.action()) {
        case LFUN_MOUSE_RELEASE:
-               // if the derived inset did not explicitly handle mouse_release,
-               // we assume we request the settings dialog
-               if (!cur.selection() && cmd.button() == mouse_button::button1
+               // If the derived inset did not explicitly handle mouse_release,
+               // we assume we request the settings dialog,
+               // except if we are about to select (MOUSE_MOTION that started
+               // outside the inset).
+               if ((!cur.selection() || covers(cur.bv(), 
cur.bv().cursor().xClickPos(),
+                                               cur.bv().cursor().yClickPos()))
+                   && cmd.button() == mouse_button::button1
                    && clickable(cur.bv(), cmd.x(), cmd.y()) && hasSettings()) {
                        FuncRequest tmpcmd(LFUN_INSET_SETTINGS);
                        dispatch(cur, tmpcmd);
diff --git a/src/insets/InsetCollapsible.cpp b/src/insets/InsetCollapsible.cpp
index 81b4561..20fbfe5 100644
--- a/src/insets/InsetCollapsible.cpp
+++ b/src/insets/InsetCollapsible.cpp
@@ -445,6 +445,8 @@ docstring const InsetCollapsible::getNewLabel(docstring 
const & l) const
 void InsetCollapsible::edit(Cursor & cur, bool front, EntryDirection 
entry_from)
 {
        //lyxerr << "InsetCollapsible: edit left/right" << endl;
+       // We might have a selection if we moved the mouse on the button only
+       cur.clearSelection();
        cur.push(*this);
        InsetText::edit(cur, front, entry_from);
 }
@@ -518,9 +520,11 @@ void InsetCollapsible::doDispatch(Cursor & cur, 
FuncRequest & cmd)
                        cur.noScreenUpdate();
                        break;
                }
-               // if we are selecting, we do not want to
-               // toggle the inset.
-               if (cur.selection())
+               // If we are selecting, we do not want to toggle the inset
+               // except if the selection started at the inset button we're 
still on.
+               // The latter addresses #12820.
+               if (cur.selection() && !clickable(cur.bv(), 
cur.bv().cursor().xClickPos(),
+                                                 
cur.bv().cursor().yClickPos()))
                        break;
                // Left button is clicked, the user asks to
                // toggle the inset visual state.
diff --git a/status.23x b/status.23x
index 48120d7..d9c09be 100644
--- a/status.23x
+++ b/status.23x
@@ -54,6 +54,9 @@ What's new
 
 - Avoid crashing on a recursive macro definition (bug 12633).
 
+- Fix several problems where insets did not react on click on
+  the Mac (bugs 12279, 12418, 12820).
+
 - Fix issue with on-screen instant preview and the mathpazo package.
 
 
-- 
lyx-cvs mailing list
lyx-cvs@lists.lyx.org
http://lists.lyx.org/mailman/listinfo/lyx-cvs

Reply via email to