]> git.lyx.org Git - lyx.git/blobdiff - src/Row.cpp
Revert "Fixup 0cbe0d7a: avoid double redraw when completion is finished"
[lyx.git] / src / Row.cpp
index 1c17fb299283b7a66df9e7034c096d5b2136c026..102b1ea4ae9df206947a3d8fea66037cd7879c65 100644 (file)
@@ -27,6 +27,7 @@
 #include "support/lassert.h"
 #include "support/lstrings.h"
 #include "support/lyxlib.h"
+#include "support/textutils.h"
 
 #include <algorithm>
 #include <ostream>
@@ -143,8 +144,12 @@ bool Row::Element::splitAt(int const width, int next_width, bool force,
        FontMetrics::Breaks breaks = fm.breakString(str, width, next_width,
                                                 isRTL(), wrap_any | force);
 
-       // if breaking did not really work, give up
-       if (!force && breaks.front().nspc_wid > width) {
+       /** if breaking did not really work, give up
+        * case 1: we do not force break and the first element is longer than the limit;
+        * case 2: the first break occurs at the front of the string
+        */
+       if ((!force && breaks.front().nspc_wid > width)
+           || (breaks.size() > 1 && breaks.front().len == 0)) {
                if (dim.wid == 0)
                        dim.wid = fm.width(str);
                return false;
@@ -155,12 +160,6 @@ bool Row::Element::splitAt(int const width, int next_width, bool force,
        bool first = true;
        docstring::size_type i = 0;
        for (FontMetrics::Break const & brk : breaks) {
-               /* For some reason breakString can decide to break before the
-                * first character (normally we use a 0-width nbsp to prevent
-                * that). Skip leading empty elements, they are never wanted.
-                */
-               if (first && brk.len == 0 && breaks.size() > 1)
-                       continue;
                Element e(STRING, pos + i, font, change);
                e.str = str.substr(i, brk.len);
                e.endpos = e.pos + brk.len;
@@ -190,8 +189,20 @@ bool Row::Element::splitAt(int const width, int next_width, bool force,
                // first_e row should be broken after the original element
                first_e.row_flags |= BreakAfter;
        } else {
-               // Restore the after flags of the original element.
+#if 1
+               // remove the BreakAfter that got added above.
                first_e.row_flags &= ~BreakAfter;
+#else
+               // FIXME : the code below looks like a good idea, but I do not
+               //         have a use case yet. The question is what happens
+               //         when breaking at the end of a string with a
+               //         trailing space.
+               // if it turns out that no breaking was necessary, remove the
+               // BreakAfter that got added above.
+               if (first_e.dim.wid <= width)
+                       first_e.row_flags &= ~BreakAfter;
+#endif
+               // Restore the after flags of the original element.
                first_e.row_flags |= row_flags & AfterFlags;
        }
 
@@ -203,14 +214,13 @@ bool Row::Element::splitAt(int const width, int next_width, bool force,
 
 void Row::Element::rtrim()
 {
-       if (type != STRING)
+       if (type != STRING || str.empty() || !isSpace(str.back()))
                return;
        /* This is intended for strings that have been created by splitAt.
-        * They may have trailing spaces, but they are not counted in the
-        * string length (QTextLayout feature, actually). We remove them,
-        * and decrease endpos, since spaces at row break are invisible.
+        * If There is a trailing space, we remove it and decrease endpos,
+        * since spaces at row break are invisible.
         */
-       str = support::rtrim(str);
+       str.pop_back();
        endpos = pos + str.length();
        dim.wid = nspc_wid;
 }
@@ -328,7 +338,7 @@ ostream & operator<<(ostream & os, Row::Elements const & elts)
 
 ostream & operator<<(ostream & os, Row const & row)
 {
-       os << " pos: " << row.pos_ << " end: " << row.end_
+       os << " pit: " << row.pit_ << " pos: " << row.pos_ << " end: " << row.end_
           << " left_margin: " << row.left_margin
           << " width: " << row.dim_.wid
           << " right_margin: " << row.right_margin
@@ -337,7 +347,8 @@ ostream & operator<<(ostream & os, Row const & row)
           << " separator: " << row.separator
           << " label_hfill: " << row.label_hfill
           << " end_boundary: " << row.end_boundary()
-          << " flushed: " << row.flushed() << "\n";
+          << " flushed: " << row.flushed_
+          << " rtl=" << row.rtl_ << "\n";
        // We cannot use the operator above, unfortunately
        double x = row.left_margin;
        for (Row::Element const & e : row.elements_) {