From eebf03aa09e7366d68f3d16fa8ecdfc8ca4b8d01 Mon Sep 17 00:00:00 2001 From: com3dian Date: Sat, 3 Aug 2024 13:11:10 +0200 Subject: [PATCH 1/2] Update `QMarkdownTextEdit::handleBracketClosing` to fix #207 Adjusted index calculation in line 720 to include removed white-space; --- qmarkdowntextedit.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/qmarkdowntextedit.cpp b/qmarkdowntextedit.cpp index 13f769f..d3183cf 100644 --- a/qmarkdowntextedit.cpp +++ b/qmarkdowntextedit.cpp @@ -717,7 +717,7 @@ bool QMarkdownTextEdit::handleBracketClosing(const QChar openingCharacter, // Remove whitespace at start of string (e.g. in multilevel-lists). const QString text = cursor.block().text().remove(QRegularExpression("^\\s+")); - const int pib = cursor.positionInBlock(); + const int pib = cursor.positionInBlock() - cursor.block().text().length() + text.length(); bool isPreviousAsterisk = pib > 0 && pib < text.length() && text.at(pib - 1) == '*'; bool isNextAsterisk = pib < text.length() && text.at(pib) == '*'; bool isMaybeBold = isPreviousAsterisk && isNextAsterisk; From dbd79a1324aee61f0593fcc029e04cf12dc27ff6 Mon Sep 17 00:00:00 2001 From: com3dian Date: Sun, 4 Aug 2024 16:36:37 +0200 Subject: [PATCH 2/2] Update QMarkdownTextEdit::handleBracketClosing to fix #207 Add brackets to subtract the length of leading spaces; --- qmarkdowntextedit.cpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/qmarkdowntextedit.cpp b/qmarkdowntextedit.cpp index d3183cf..7fab3f5 100644 --- a/qmarkdowntextedit.cpp +++ b/qmarkdowntextedit.cpp @@ -716,8 +716,9 @@ bool QMarkdownTextEdit::handleBracketClosing(const QChar openingCharacter, // get the current text from the block (inserted character not included) // Remove whitespace at start of string (e.g. in multilevel-lists). const QString text = cursor.block().text().remove(QRegularExpression("^\\s+")); + // Subtract the length of leading whitespace + const int pib = cursor.positionInBlock() - (cursor.block().text().length() - text.length()); - const int pib = cursor.positionInBlock() - cursor.block().text().length() + text.length(); bool isPreviousAsterisk = pib > 0 && pib < text.length() && text.at(pib - 1) == '*'; bool isNextAsterisk = pib < text.length() && text.at(pib) == '*'; bool isMaybeBold = isPreviousAsterisk && isNextAsterisk;