From bbc775909cb0e224d0a1ef38663add2bf9c91721 Mon Sep 17 00:00:00 2001 From: Albert Astals Cid Date: Tue, 28 Sep 2021 23:19:38 +0200 Subject: [PATCH] markdown: Only remove text if we're going to add something Otherwise things get confused BUGS: 443057 (cherry picked from commit 3b8cbc33204be4a88df56150078d42149b0dc6cf) --- generators/markdown/converter.cpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/generators/markdown/converter.cpp b/generators/markdown/converter.cpp index 7ca2e582f..2f7fd9ebf 100644 --- a/generators/markdown/converter.cpp +++ b/generators/markdown/converter.cpp @@ -194,10 +194,10 @@ void Converter::convertImages(const QTextBlock &parent, const QDir &dir, QTextDo QTextCursor cursor(textDocument); cursor.setPosition(textFragment.position(), QTextCursor::MoveAnchor); cursor.setPosition(textFragment.position() + textFragment.length(), QTextCursor::KeepAnchor); - cursor.removeSelectedText(); const QString imageFilePath = QDir::cleanPath(dir.absoluteFilePath(textCharFormat.toImageFormat().name())); if (QFile::exists(imageFilePath)) { + cursor.removeSelectedText(); format.setName(imageFilePath); const QImage img = QImage(format.name()); @@ -206,6 +206,7 @@ void Converter::convertImages(const QTextBlock &parent, const QDir &dir, QTextDo cursor.insertImage(format); #if QT_VERSION >= QT_VERSION_CHECK(5, 14, 0) } else if ((!textCharFormat.toImageFormat().property(QTextFormat::ImageAltText).toString().isEmpty())) { + cursor.removeSelectedText(); cursor.insertText(textCharFormat.toImageFormat().property(QTextFormat::ImageAltText).toString()); #endif }