commit 1dbe589b2731978e01f57720c3c88f0d84750c0d
Author: Jean-Marc Lasgouttes <[email protected]>
Date:   Mon Nov 25 16:59:20 2024 +0100

    Use setCursorFromCoordinates when scrolling
    
    This is better that rewriting yet another version of the same code.
---
 src/TextMetrics.cpp              |  2 +-
 src/frontends/qt/GuiWorkArea.cpp | 31 +++----------------------------
 2 files changed, 4 insertions(+), 29 deletions(-)

diff --git a/src/TextMetrics.cpp b/src/TextMetrics.cpp
index 48215c0216..d14f5808c3 100644
--- a/src/TextMetrics.cpp
+++ b/src/TextMetrics.cpp
@@ -1632,7 +1632,7 @@ void TextMetrics::setCursorFromCoordinates(Cursor & cur, 
int x, int const y)
        pit_type const pit = getPitNearY(y);
        LASSERT(pit != -1, return);
 
-       ParagraphMetrics const & pm = par_metrics_[pit];
+       ParagraphMetrics const & pm = parMetrics(pit);
 
        int yy = pm.position() - pm.rows().front().ascent();
        LYXERR(Debug::PAINTING, "x: " << x << " y: " << y <<
diff --git a/src/frontends/qt/GuiWorkArea.cpp b/src/frontends/qt/GuiWorkArea.cpp
index 63eb84168a..47ab40d427 100644
--- a/src/frontends/qt/GuiWorkArea.cpp
+++ b/src/frontends/qt/GuiWorkArea.cpp
@@ -973,7 +973,7 @@ void GuiWorkArea::generateSyntheticMouseEvent()
        Text * text = cur.text();
        if (!text)
                return;
-       TextMetrics const & tm = d->buffer_view_->textMetrics(text);
+       TextMetrics & tm = d->buffer_view_->textMetrics(text);
 
        // FIXME: use TextMetrics::setCursorFromCoordinates.
        // Quit gracefully if there are no metrics, since otherwise next
@@ -982,33 +982,8 @@ void GuiWorkArea::generateSyntheticMouseEvent()
        if (tm.empty())
                return;
 
-       pair<pit_type, const ParagraphMetrics *> pp = up ? tm.first() : 
tm.last();
-       ParagraphMetrics const & pm = *pp.second;
-       pit_type const pit = pp.first;
-
-       if (pm.rows().empty())
-               return;
-
-       // Find the row at which we set the cursor.
-       RowList::const_iterator rit = pm.rows().begin();
-       RowList::const_iterator rlast = pm.rows().end();
-       int yy = pm.top();
-       for (--rlast; rit != rlast; ++rit) {
-               int h = rit->height();
-               if ((up && yy + h > 0)
-                         || (!up && yy + h > wh - defaultRowHeight()))
-                       break;
-               yy += h;
-       }
-
-       // Find the position of the cursor
-       int x = d->synthetic_mouse_event_.cmd.x();
-       auto [pos, bound] = tm.getPosNearX(*rit, x);
-
-       // Set the cursor
-       cur.pit() = pit;
-       cur.pos() = pos;
-       cur.boundary(bound);
+       const int y = up ? 0 : wh - defaultRowHeight();
+       tm.setCursorFromCoordinates(cur, d->synthetic_mouse_event_.cmd.x(), y);
 
        d->buffer_view_->buffer().changed(false);
 }
-- 
lyx-cvs mailing list
[email protected]
https://lists.lyx.org/mailman/listinfo/lyx-cvs

Reply via email to