]> git.lyx.org Git - features.git/commitdiff
Fix flicker due to changing metrics while selecting with the mouse
authorJean-Marc Lasgouttes <lasgouttes@lyx.org>
Fri, 22 Jul 2022 23:57:56 +0000 (01:57 +0200)
committerJean-Marc Lasgouttes <lasgouttes@lyx.org>
Mon, 25 Jul 2022 21:04:08 +0000 (23:04 +0200)
This patch has been backported from the lyx-unstable branch
https://gitlab.com/gadmm/lyx-unstable/-/commit/9d7ed42389ba

Actual author is Guillaume Munch.

Fixes bug #8951.

src/BufferView.cpp
src/BufferView.h
src/frontends/qt/GuiWorkArea.cpp
src/insets/Inset.cpp
src/mathed/InsetMathMacro.cpp

index 72cbb2874dea0acf385b41ddabce7842d44ffbad..6f1b412a5b3913473516040cdcf94734b7215d20 100644 (file)
@@ -292,6 +292,8 @@ struct BufferView::Private
        bool clickable_inset_;
        /// shape of the caret
        frontend::CaretGeometry caret_geometry_;
+       ///
+       bool mouse_selecting_ = false;
 };
 
 
@@ -2466,6 +2468,12 @@ void BufferView::clearLastInset(Inset * inset) const
 }
 
 
+bool BufferView::mouseSelecting() const
+{
+       return d->mouse_selecting_;
+}
+
+
 void BufferView::mouseEventDispatch(FuncRequest const & cmd0)
 {
        //lyxerr << "[ cmd0 " << cmd0 << "]" << endl;
@@ -2488,6 +2496,9 @@ void BufferView::mouseEventDispatch(FuncRequest const & cmd0)
        d->mouse_position_cache_.x_ = cmd.x();
        d->mouse_position_cache_.y_ = cmd.y();
 
+       d->mouse_selecting_ =
+               cmd.action() == LFUN_MOUSE_MOTION && cmd.button() == mouse_button::button1;
+
        if (cmd.action() == LFUN_MOUSE_MOTION && cmd.button() == mouse_button::none) {
                updateHoveredInset();
                return;
index 210200a47c1dc7356653e755846df73a534458e0..ad725f2121861a598cc5c724758c4bc214035302 100644 (file)
@@ -375,6 +375,8 @@ public:
        bool clickableInset() const;
        ///
        void makeDocumentClass();
+       /// Are we currently performing a selection with the mouse?
+       bool mouseSelecting() const;
 
 private:
        /// noncopyable
index 900273f03877ef46cc024a79ef8002bc3083fd50..802fbc71b70d8867c6d5ae7284f1aa791b430121 100644 (file)
@@ -429,7 +429,7 @@ void GuiWorkArea::Private::dispatch(FuncRequest const & cmd)
 
        // Skip these when selecting
        // FIXME: let GuiView take care of those.
-       if (cmd.action() != LFUN_MOUSE_MOTION) {
+       if (notJustMovingTheMouse && !buffer_view_->mouseSelecting()) {
                completer_->updateVisibility(false, false);
                lyx_view_->updateDialogs();
                lyx_view_->updateStatusBar();
index 7d05c8ef1fa3097e8ae9cc8af773232e894ad969..3b00c0caa2b9fd0abcbe89d3c0c86cf67e37b62b 100644 (file)
@@ -584,7 +584,12 @@ void Inset::drawMarkers(PainterInfo & pi, int x, int y) const
 
 bool Inset::editing(BufferView const * bv) const
 {
-       return bv->cursor().isInside(this);
+       if (bv->mouseSelecting())
+               // Avoid flicker when selecting with the mouse: when so, do not make
+               // decisions about metrics based on the mouse location.
+               return bv->cursor().realAnchor().isInside(this);
+       else
+               return bv->cursor().isInside(this);
 }
 
 
index f6efc70cf7702582edbe66531d042850ffb3b7c9..5de0c1a789d2ab7fb5c92e1d4d762b3a51a905c4 100644 (file)
@@ -511,7 +511,10 @@ void InsetMathMacro::cursorPos(BufferView const & bv,
 
 bool InsetMathMacro::editMode(BufferView const * bv) const {
        // find this in cursor trace
-       Cursor const & cur = bv->cursor();
+       DocIterator const & cur =
+               // Do not move the reference while selecting with the mouse to avoid
+               // flicker due to changing metrics
+               bv->mouseSelecting() ? bv->cursor().realAnchor() : bv->cursor();
        for (size_t i = 0; i != cur.depth(); ++i)
                if (&cur[i].inset() == this) {
                        // look if there is no other macro in edit mode above