diff options
Diffstat (limited to 'src/gui/text/qtextdocumentfragment.cpp')
-rw-r--r-- | src/gui/text/qtextdocumentfragment.cpp | 29 |
1 files changed, 15 insertions, 14 deletions
diff --git a/src/gui/text/qtextdocumentfragment.cpp b/src/gui/text/qtextdocumentfragment.cpp index 0118c34c97..1b6e76c201 100644 --- a/src/gui/text/qtextdocumentfragment.cpp +++ b/src/gui/text/qtextdocumentfragment.cpp @@ -84,7 +84,7 @@ int QTextCopyHelper::appendFragment(int pos, int endPos, int objectIndex) } QString txtToInsert(originalText.constData() + frag->stringPosition + inFragmentOffset, charsToCopy); - if (txtToInsert.length() == 1 + if (txtToInsert.size() == 1 && (txtToInsert.at(0) == QChar::ParagraphSeparator || txtToInsert.at(0) == QTextBeginningOfFrame || txtToInsert.at(0) == QTextEndOfFrame @@ -109,7 +109,7 @@ int QTextCopyHelper::appendFragment(int pos, int endPos, int objectIndex) const int userState = nextBlock.userState(); if (userState != -1) dst->blocksFind(insertPos).setUserState(userState); - insertPos += txtToInsert.length(); + insertPos += txtToInsert.size(); } return charsToCopy; @@ -488,7 +488,8 @@ void QTextHtmlImporter::import() * means there was a tag closing in the input html */ if (currentNodeIdx > 0 && (currentNode->parent != currentNodeIdx - 1)) { - blockTagClosed = closeTag(); + const bool lastBlockTagClosed = closeTag(); + blockTagClosed = blockTagClosed || lastBlockTagClosed; // visually collapse subsequent block tags, but if the element after the closed block tag // is for example an inline element (!isBlock) we have to make sure we start a new paragraph by setting // hasBlock to false. @@ -540,6 +541,7 @@ void QTextHtmlImporter::import() appendBlock(block, currentNode->charFormat); + blockTagClosed = false; hasBlock = true; } @@ -575,14 +577,12 @@ bool QTextHtmlImporter::appendNodeText() if (wsm == QTextHtmlParserNode::WhiteSpacePre || wsm == QTextHtmlParserNode::WhiteSpacePreWrap) compressNextWhitespace = PreserveWhiteSpace; - QString text = currentNode->text; + const QString text = currentNode->text; QString textToInsert; textToInsert.reserve(text.size()); - for (int i = 0; i < text.length(); ++i) { - QChar ch = text.at(i); - + for (QChar ch : text) { if (ch.isSpace() && ch != QChar::Nbsp && ch != QChar::ParagraphSeparator) { @@ -621,7 +621,7 @@ bool QTextHtmlImporter::appendNodeText() || ch == QChar::ParagraphSeparator) { if (!textToInsert.isEmpty()) { - if (wsm == QTextHtmlParserNode::WhiteSpacePreLine && textToInsert.at(textToInsert.length() - 1) == u' ') + if (wsm == QTextHtmlParserNode::WhiteSpacePreLine && textToInsert.at(textToInsert.size() - 1) == u' ') textToInsert = textToInsert.chopped(1); cursor.insertText(textToInsert, format); textToInsert.clear(); @@ -699,6 +699,8 @@ QTextHtmlImporter::ProcessNodeResult QTextHtmlImporter::processSpecialNodes() listFmt.setNumberPrefix(currentNode->textListNumberPrefix); if (!currentNode->textListNumberSuffix.isNull()) listFmt.setNumberSuffix(currentNode->textListNumberSuffix); + if (currentNode->listStart != 1) + listFmt.setStart(currentNode->listStart); ++indent; if (currentNode->hasCssListIndent) @@ -906,7 +908,7 @@ QTextHtmlImporter::Table QTextHtmlImporter::scanTable(int tableNodeIdx) int tableHeaderRowCount = 0; QList<int> rowNodes; - rowNodes.reserve(at(tableNodeIdx).children.count()); + rowNodes.reserve(at(tableNodeIdx).children.size()); for (int row : at(tableNodeIdx).children) { switch (at(row).id) { case Html_tr: @@ -931,7 +933,7 @@ QTextHtmlImporter::Table QTextHtmlImporter::scanTable(int tableNodeIdx) QList<RowColSpanInfo> rowColSpanForColumn; int effectiveRow = 0; - for (int row : qAsConst(rowNodes)) { + for (int row : std::as_const(rowNodes)) { int colsInRow = 0; for (int cell : at(row).children) { @@ -959,7 +961,7 @@ QTextHtmlImporter::Table QTextHtmlImporter::scanTable(int tableNodeIdx) if (spanInfo.colSpan > 1 || spanInfo.rowSpan > 1) rowColSpans.append(spanInfo); - columnWidths.resize(qMax(columnWidths.count(), colsInRow)); + columnWidths.resize(qMax(columnWidths.size(), colsInRow)); rowColSpanForColumn.resize(columnWidths.size()); for (int i = currentColumn; i < currentColumn + c.tableCellColSpan; ++i) { if (columnWidths.at(i).type() == QTextLength::VariableLength) { @@ -1041,7 +1043,7 @@ QTextHtmlImporter::Table QTextHtmlImporter::scanTable(int tableNodeIdx) QTextTable *textTable = cursor.insertTable(table.rows, table.columns, fmt.toTableFormat()); table.frame = textTable; - for (int i = 0; i < rowColSpans.count(); ++i) { + for (int i = 0; i < rowColSpans.size(); ++i) { const RowColSpanInfo &nfo = rowColSpans.at(i); textTable->mergeCells(nfo.row, nfo.col, nfo.rowSpan, nfo.colSpan); } @@ -1311,8 +1313,7 @@ QTextDocumentFragment QTextDocumentFragment::fromMarkdown(const QString &markdow QTextDocumentFragment res; res.d = new QTextDocumentFragmentPrivate; - QTextMarkdownImporter importer(features); - importer.import(res.d->doc, markdown); + QTextMarkdownImporter(res.d->doc, features).import(markdown); return res; } |