diff --git a/src/plugins/texteditor/basetexteditor.cpp b/src/plugins/texteditor/basetexteditor.cpp
index b9ced9c9a416a9e8ae0ea9af3b93d446e53a6a24..3bc8283b1b0a2d8bc761266d8705d133a8f41723 100644
--- a/src/plugins/texteditor/basetexteditor.cpp
+++ b/src/plugins/texteditor/basetexteditor.cpp
@@ -4733,11 +4733,14 @@ void BaseTextEditor::_q_highlightBlocks()
             while (TextBlockUserData::findPreviousBlockOpenParenthesis(&cursor, firstRun)) {
                 firstRun = false;
                 highlightBlocksInfo.open.prepend(cursor.blockNumber());
-                highlightBlocksInfo.visualIndent.prepend(d->visualIndent(cursor.block()));
+                int visualIndent = d->visualIndent(cursor.block());
                 if (closeCursor.isNull())
                     closeCursor = cursor;
-                if (TextBlockUserData::findNextBlockClosingParenthesis(&closeCursor))
+                if (TextBlockUserData::findNextBlockClosingParenthesis(&closeCursor)) {
                     highlightBlocksInfo.close.append(closeCursor.blockNumber());
+                    visualIndent = qMin(visualIndent, d->visualIndent(closeCursor.block()));
+                }
+                highlightBlocksInfo.visualIndent.prepend(visualIndent);
             }
         }
     }