On Mon, Nov 25, 2024 at 04:36:01PM +0000, Jean-Marc Lasgouttes wrote:
> commit 6701a5d55c17e66c0db466d6a0cc52ce2883329e
> Author: Jean-Marc Lasgouttes <lasgout...@lyx.org>
> Date:   Mon Nov 25 17:34:43 2024 +0100
> 
>     Get rid of TextMetrics::x2pos
>     
>     Replace it with code that uses getPosNearX.
> ---
>  src/TextMetrics.cpp         | 15 ---------------
>  src/TextMetrics.h           |  6 ------
>  src/insets/InsetTabular.cpp | 15 +++++++--------
>  3 files changed, 7 insertions(+), 29 deletions(-)
> 
> diff --git a/src/TextMetrics.cpp b/src/TextMetrics.cpp
> index d14f5808c3..1f56a46c76 100644
> --- a/src/TextMetrics.cpp
> +++ b/src/TextMetrics.cpp
> @@ -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)
>  {
> diff --git a/src/TextMetrics.h b/src/TextMetrics.h
> index 69d0e4853b..4f49f0fa7d 100644
> --- a/src/TextMetrics.h
> +++ b/src/TextMetrics.h
> @@ -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.
> diff --git a/src/insets/InsetTabular.cpp b/src/insets/InsetTabular.cpp
> index e9050c4fb3..016d90a692 100644
> --- a/src/insets/InsetTabular.cpp
> +++ b/src/insets/InsetTabular.cpp
> @@ -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();

Just out of curiosity, why drop the const? Does new code change
'xtarget' or just a style preference?

Scott


>                               // 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();
>                       }
>               }
> -- 
> lyx-cvs mailing list
> lyx-...@lists.lyx.org
> https://lists.lyx.org/mailman/listinfo/lyx-cvs

Attachment: signature.asc
Description: PGP signature

-- 
lyx-devel mailing list
lyx-devel@lists.lyx.org
https://lists.lyx.org/mailman/listinfo/lyx-devel

Reply via email to