]> git.lyx.org Git - features.git/commitdiff
Do not use a fake row to compute completion dimension
authorJean-Marc Lasgouttes <lasgouttes@lyx.org>
Tue, 22 Sep 2020 13:06:46 +0000 (15:06 +0200)
committerJean-Marc Lasgouttes <lasgouttes@lyx.org>
Tue, 22 Sep 2020 13:11:08 +0000 (15:11 +0200)
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

index ea594e9b9904f8a47d423df830283422f62bca44..681985bd73c46033de29b0466fbca68e413b49c1 100644 (file)
@@ -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
 {
 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?
 
        // 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
        dim.wid = abs(rxy.x_ - lxy.x_);
 
        // calculate position of word