]> git.lyx.org Git - features.git/commitdiff
Avoid endless loop when the window is too narrow
authorJean-Marc Lasgouttes <lasgouttes@lyx.org>
Wed, 2 Mar 2016 22:59:40 +0000 (23:59 +0100)
committerJean-Marc Lasgouttes <lasgouttes@lyx.org>
Thu, 3 Mar 2016 17:08:11 +0000 (18:08 +0100)
 * breakRow: remove wrong condition that would silently eat the contents of the
   paragraph when the window is narrower than left margin

 * breakRow: make sure that there is at least one element in each row

 * breakAt: when force-breaking a row element, make sure it is not empty. Doing
   so may create empty rows and therefore a endless loop.

Fixes bugs #9962 and #10001.

src/TextMetrics.cpp
src/frontends/qt4/GuiFontMetrics.cpp

index cb1c4bd2bd16c98095c1060d2ee7ee19627e4ff4..f37e6780d1739b03ac45b99b3c6b671b32c36ab8 100644 (file)
@@ -803,7 +803,7 @@ void TextMetrics::breakRow(Row & row, int const right_margin, pit_type const pit
        // the width available for the row.
        int const width = max_width_ - row.right_margin;
 
-       if (pos >= end || row.width() > width) {
+       if (pos >= end) {
                row.endpos(end);
                return;
        }
@@ -828,7 +828,7 @@ void TextMetrics::breakRow(Row & row, int const right_margin, pit_type const pit
        // or the end of the par, then build a representation of the row.
        pos_type i = pos;
        FontIterator fi = FontIterator(*this, par, pit, pos);
-       while (i < end && row.width() <= width) {
+       do {
                char_type c = par.getChar(i);
                // The most special cases are handled first.
                if (par.isInset(i)) {
@@ -893,7 +893,7 @@ void TextMetrics::breakRow(Row & row, int const right_margin, pit_type const pit
 
                ++i;
                ++fi;
-       }
+       } while (i < end && row.width() <= width);
        row.finalizeLast();
        row.endpos(i);
 
index fdb8c73bc6d25f91e4414d2900d4c97917139a2e..eade8ccc6ce266139b4c5ecd53d81b9cdb602261 100644 (file)
@@ -240,7 +240,7 @@ bool GuiFontMetrics::breakAt(docstring & s, int & x, bool const rtl, bool const
        line.setLineWidth(x);
        tl.createLine();
        tl.endLayout();
-       if (int(line.naturalTextWidth()) > x)
+       if ((force && line.textLength() == 1) || int(line.naturalTextWidth()) > x)
                return false;
        x = int(line.naturalTextWidth());
        // The -1 is here to account for the leading zerow_nbsp.