Get rid of TextMetrics::x2pos

Replace it with code that uses getPosNearX.
This commit is contained in:
Jean-Marc Lasgouttes 2024-11-25 17:34:43 +01:00
parent 4c72def295
commit 6701a5d55c
3 changed files with 7 additions and 29 deletions

View File

@ -1454,21 +1454,6 @@ pair<pos_type, bool> TextMetrics::getPosNearX(Row const & row, int & x) const
}
// FIXME: only InsetTabular uses this. Remove?
pos_type TextMetrics::x2pos(pit_type pit, int row, int x) const
{
// We play safe and use parMetrics(pit) to make sure the
// ParagraphMetrics will be redone and OK to use if needed.
// Otherwise we would use an empty ParagraphMetrics in
// upDownInText() while in selection mode.
ParagraphMetrics const & pm = parMetrics(pit);
LBUFERR(row < int(pm.rows().size()));
Row const & r = pm.rows()[row];
return getPosNearX(r, x).first;
}
// y is screen coordinate
pit_type TextMetrics::getPitNearY(int y)
{

View File

@ -191,12 +191,6 @@ public:
/// of this column. This takes in account horizontal cursor row scrolling.
std::pair<pos_type, bool> getPosNearX(Row const & row, int & x) const;
/// returns pos in given par at given x coord.
pos_type x2pos(pit_type pit, int row, int x) const;
// FIXME: is there a need for this?
//int pos2x(pit_type pit, pos_type pos) const;
/// returns the row near the specified y-coordinate in a given paragraph
/// (relative to the screen). If assert_in_view is true, it is made sure
/// that the row is on screen completely; this might change the given pit.

View File

@ -5292,15 +5292,15 @@ void InsetTabular::doDispatch(Cursor & cur, FuncRequest & cmd)
// setting also the right targetX.
cur.selHandle(act == LFUN_DOWN_SELECT);
if (tabular.cellRow(cur.idx()) != tabular.nrows() - 1) {
int const xtarget = cur.targetX();
int xtarget = cur.targetX();
// WARNING: Once cur.idx() has been reset, the cursor is in
// an inconsistent state until pos() has been set. Be careful
// what you do with it!
cur.idx() = tabular.cellBelow(cur.idx());
cur.pit() = 0;
TextMetrics const & tm =
cur.bv().textMetrics(cell(cur.idx())->getText(0));
cur.pos() = tm.x2pos(cur.pit(), 0, xtarget);
TextMetrics const & tm = cur.bv().textMetrics(cell(cur.idx())->getText(0));
ParagraphMetrics const & pm = tm.parMetrics(cur.pit());
cur.pos() = tm.getPosNearX(pm.rows().front(), xtarget).first;
cur.setCurrentFont();
}
}
@ -5331,7 +5331,7 @@ void InsetTabular::doDispatch(Cursor & cur, FuncRequest & cmd)
// setting also the right targetX.
cur.selHandle(act == LFUN_UP_SELECT);
if (tabular.cellRow(cur.idx()) != 0) {
int const xtarget = cur.targetX();
int xtarget = cur.targetX();
// WARNING: Once cur.idx() has been reset, the cursor is in
// an inconsistent state until pos() has been set. Be careful
// what you do with it!
@ -5339,9 +5339,8 @@ void InsetTabular::doDispatch(Cursor & cur, FuncRequest & cmd)
cur.pit() = cur.lastpit();
Text const * text = cell(cur.idx())->getText(0);
TextMetrics const & tm = cur.bv().textMetrics(text);
ParagraphMetrics const & pm =
tm.parMetrics(cur.lastpit());
cur.pos() = tm.x2pos(cur.pit(), pm.rows().size()-1, xtarget);
ParagraphMetrics const & pm = tm.parMetrics(cur.lastpit());
cur.pos() = tm.getPosNearX(pm.rows().back(), xtarget).first;
cur.setCurrentFont();
}
}