From 76fbe75abee7d77911467d56630176f777e8ed78 Mon Sep 17 00:00:00 2001 From: Rainer Keller Date: Tue, 7 Jan 2020 09:13:21 +0100 Subject: Remove empty block at beginning of imported markdown An empty QTextDocument already contains a block; so when the formatting is fully determined, if the document is still empty, then instead of inserting a new block, we can set formatting on the cursor, which affects the pre-existing block, before inserting text. This avoids leaving a blank line (the default block) above the inserted content. Fixes: QTBUG-81060 Change-Id: I14e45e300a602493aa59680417d74d4c2b25862d Reviewed-by: Shawn Rutledge --- src/gui/text/qtextmarkdownimporter.cpp | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) (limited to 'src') diff --git a/src/gui/text/qtextmarkdownimporter.cpp b/src/gui/text/qtextmarkdownimporter.cpp index 78d18a714b..88965046ce 100644 --- a/src/gui/text/qtextmarkdownimporter.cpp +++ b/src/gui/text/qtextmarkdownimporter.cpp @@ -207,7 +207,12 @@ int QTextMarkdownImporter::cbEnterBlock(int blockType, void *det) charFmt.setFontWeight(QFont::Bold); blockFmt.setHeadingLevel(int(detail->level)); m_needsInsertBlock = false; - m_cursor->insertBlock(blockFmt, charFmt); + if (m_doc->isEmpty()) { + m_cursor->setBlockFormat(blockFmt); + m_cursor->setCharFormat(charFmt); + } else { + m_cursor->insertBlock(blockFmt, charFmt); + } qCDebug(lcMD, "H%d", detail->level); } break; case MD_BLOCK_LI: { @@ -592,7 +597,12 @@ void QTextMarkdownImporter::insertBlock() blockFormat.setMarker(m_markerType); if (!m_listStack.isEmpty()) blockFormat.setIndent(m_listStack.count()); - m_cursor->insertBlock(blockFormat, charFormat); + if (m_doc->isEmpty()) { + m_cursor->setBlockFormat(blockFormat); + m_cursor->setCharFormat(charFormat); + } else { + m_cursor->insertBlock(blockFormat, charFormat); + } if (m_needsInsertList) { m_listStack.push(m_cursor->createList(m_listFormat)); } else if (!m_listStack.isEmpty() && m_listItem) { -- cgit v1.2.3