Use setCursorFromCoordinates when scrolling

This is better that rewriting yet another version of the same code.
This commit is contained in:
Jean-Marc Lasgouttes 2024-11-25 16:59:20 +01:00
parent 91d1ad319d
commit 1dbe589b27
2 changed files with 4 additions and 29 deletions

View File

@ -1632,7 +1632,7 @@ void TextMetrics::setCursorFromCoordinates(Cursor & cur, int x, int const y)
pit_type const pit = getPitNearY(y); pit_type const pit = getPitNearY(y);
LASSERT(pit != -1, return); LASSERT(pit != -1, return);
ParagraphMetrics const & pm = par_metrics_[pit]; ParagraphMetrics const & pm = parMetrics(pit);
int yy = pm.position() - pm.rows().front().ascent(); int yy = pm.position() - pm.rows().front().ascent();
LYXERR(Debug::PAINTING, "x: " << x << " y: " << y << LYXERR(Debug::PAINTING, "x: " << x << " y: " << y <<

View File

@ -973,7 +973,7 @@ void GuiWorkArea::generateSyntheticMouseEvent()
Text * text = cur.text(); Text * text = cur.text();
if (!text) if (!text)
return; return;
TextMetrics const & tm = d->buffer_view_->textMetrics(text); TextMetrics & tm = d->buffer_view_->textMetrics(text);
// FIXME: use TextMetrics::setCursorFromCoordinates. // FIXME: use TextMetrics::setCursorFromCoordinates.
// Quit gracefully if there are no metrics, since otherwise next // Quit gracefully if there are no metrics, since otherwise next
@ -982,33 +982,8 @@ void GuiWorkArea::generateSyntheticMouseEvent()
if (tm.empty()) if (tm.empty())
return; return;
pair<pit_type, const ParagraphMetrics *> pp = up ? tm.first() : tm.last(); const int y = up ? 0 : wh - defaultRowHeight();
ParagraphMetrics const & pm = *pp.second; tm.setCursorFromCoordinates(cur, d->synthetic_mouse_event_.cmd.x(), y);
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);
d->buffer_view_->buffer().changed(false); d->buffer_view_->buffer().changed(false);
} }