[LyX/master] Do not use a fake row to compute completion dimension
Jean-Marc Lasgouttes
lasgouttes at lyx.org
Tue Sep 22 12:44:28 UTC 2020
commit 32b688225d49582066da3c2027ea8308915fef66
Author: Jean-Marc Lasgouttes <lasgouttes at lyx.org>
Date: Tue Sep 22 15:06:46 2020 +0200
Do not use a fake row to compute completion dimension
The code in TextMetrics::completionPosAndDim is needlessly complicated.
1/ It is easier to rely directly on Text::getWord() rather than on the
helper previousWord().
2/ Using a fake row to compute completion height is overkill. A
simpler solution is proposed here.
No intended effect. These changes prepare the fix to ticket #11818.
---
src/TextMetrics.cpp | 28 ++++++++++++----------------
1 files changed, 12 insertions(+), 16 deletions(-)
diff --git a/src/TextMetrics.cpp b/src/TextMetrics.cpp
index ea594e9..681985b 100644
--- a/src/TextMetrics.cpp
+++ b/src/TextMetrics.cpp
@@ -1994,26 +1994,22 @@ void TextMetrics::drawParagraph(PainterInfo & pi, pit_type const pit, int const
void TextMetrics::completionPosAndDim(Cursor const & cur, int & x, int & y,
Dimension & dim) const
{
- Cursor const & bvcur = cur.bv().cursor();
+ DocIterator from = cur.bv().cursor();
+ DocIterator to = from;
+ text_->getWord(from.top(), to.top(), PREVIOUS_WORD);
- // get word in front of cursor
- docstring word = text_->previousWord(bvcur.top());
- DocIterator wordStart = bvcur;
- wordStart.pos() -= word.length();
-
- // calculate dimensions of the word
- Row row;
- row.pit(bvcur.pit());
- row.pos(wordStart.pos());
- row.endpos(bvcur.pos());
- setRowHeight(row);
- dim = row.dim();
+ // The vertical dimension of the word
+ Font const font = displayFont(cur.pit(), from.pos());
+ FontMetrics const & fm = theFontMetrics(font);
+ // the +1's below are related to the extra pixels added in setRowHeight
+ dim.asc = fm.maxAscent() + 1;
+ dim.des = fm.maxDescent() + 1;
// get position on screen of the word start and end
//FIXME: Is it necessary to explicitly set this to false?
- wordStart.boundary(false);
- Point lxy = cur.bv().getPos(wordStart);
- Point rxy = cur.bv().getPos(bvcur);
+ from.boundary(false);
+ Point lxy = cur.bv().getPos(from);
+ Point rxy = cur.bv().getPos(to);
dim.wid = abs(rxy.x_ - lxy.x_);
// calculate position of word
More information about the lyx-cvs
mailing list