diff options
author | Shawn Rutledge <shawn.rutledge@qt.io> | 2019-05-20 11:50:26 +0200 |
---|---|---|
committer | Shawn Rutledge <shawn.rutledge@qt.io> | 2019-05-24 15:37:05 +0200 |
commit | 280d679c556ab8ead4748a627d7cd4c1950027fb (patch) | |
tree | 56907c874f5d7272af016069a849ae272f5df063 /src | |
parent | 7224d0e427d71e559b928c44634839b4791c1416 (diff) |
QTextMarkdownWriter: fix some bad cases with word wrap
If any non-breakable content (such as a link) already went past
80 columns, or if a word ended on column 80, it didn't wrap the rest of
the paragraph following.
Change-Id: I27dc0474f18892c34ee2514ea6d5070dae29424f
Reviewed-by: Gatis Paeglis <gatis.paeglis@qt.io>
Diffstat (limited to 'src')
-rw-r--r-- | src/gui/text/qtextmarkdownwriter.cpp | 21 |
1 files changed, 18 insertions, 3 deletions
diff --git a/src/gui/text/qtextmarkdownwriter.cpp b/src/gui/text/qtextmarkdownwriter.cpp index f180098db2..02643acdca 100644 --- a/src/gui/text/qtextmarkdownwriter.cpp +++ b/src/gui/text/qtextmarkdownwriter.cpp @@ -212,10 +212,19 @@ QTextMarkdownWriter::ListInfo QTextMarkdownWriter::listInfo(QTextList *list) static int nearestWordWrapIndex(const QString &s, int before) { before = qMin(before, s.length()); + int fragBegin = qMax(before - 15, 0); + if (lcMDW().isDebugEnabled()) { + QString frag = s.mid(fragBegin, 30); + qCDebug(lcMDW) << frag << before; + qCDebug(lcMDW) << QString(before - fragBegin, Period) + QLatin1Char('<'); + } for (int i = before - 1; i >= 0; --i) { - if (s.at(i).isSpace()) + if (s.at(i).isSpace()) { + qCDebug(lcMDW) << QString(i - fragBegin, Period) + QLatin1Char('^') << i; return i; + } } + qCDebug(lcMDW, "not possible"); return -1; } @@ -251,7 +260,7 @@ static void maybeEscapeFirstChar(QString &s) int QTextMarkdownWriter::writeBlock(const QTextBlock &block, bool wrap, bool ignoreFormat) { - int ColumnLimit = 80; + const int ColumnLimit = 80; QTextBlockFormat blockFmt = block.blockFormat(); bool indentedCodeBlock = false; if (block.textList()) { // it's a list-item @@ -419,12 +428,18 @@ int QTextMarkdownWriter::writeBlock(const QTextBlock &block, bool wrap, bool ign int fragLen = fragmentText.length(); bool breakingLine = false; while (i < fragLen) { + if (col >= ColumnLimit) { + m_stream << Newline << wrapIndentString; + col = m_wrappedLineIndent; + while (fragmentText[i].isSpace()) + ++i; + } int j = i + ColumnLimit - col; if (j < fragLen) { int wi = nearestWordWrapIndex(fragmentText, j); if (wi < 0) { j = fragLen; - } else { + } else if (wi >= i) { j = wi; breakingLine = true; } |