diff --git a/src/plugins/texteditor/basetexteditor.cpp b/src/plugins/texteditor/basetexteditor.cpp index 5c3d084e211172ab710e4e3457fa718eb72b5611..9bc9ef529a65b1c5cebff8c5da2a74cf845ea638 100644 --- a/src/plugins/texteditor/basetexteditor.cpp +++ b/src/plugins/texteditor/basetexteditor.cpp @@ -3165,10 +3165,10 @@ bool TextBlockUserData::findPreviousOpenParenthesis(QTextCursor *cursor, bool se return false; } -bool TextBlockUserData::findPreviousBlockOpenParenthesis(QTextCursor *cursor) +bool TextBlockUserData::findPreviousBlockOpenParenthesis(QTextCursor *cursor, bool checkStartPosition) { QTextBlock block = cursor->block(); - int position = cursor->position(); + int position = cursor->position() + (checkStartPosition ? 1 : 0 ); int ignore = 0; while (block.isValid()) { Parentheses parenList = TextEditDocumentLayout::parentheses(block); @@ -3399,10 +3399,12 @@ void BaseTextEditor::_q_highlightBlocks() if (block.isValid()) { QTextCursor cursor(block); if (d->extraAreaHighlightCollapseColumn >= 0) - cursor.setPosition(cursor.position() + qMin(d->extraAreaHighlightCollapseColumn+1, + cursor.setPosition(cursor.position() + qMin(d->extraAreaHighlightCollapseColumn, block.length())); QTextCursor closeCursor; - while (TextBlockUserData::findPreviousBlockOpenParenthesis(&cursor)) { + bool firstRun = true; + while (TextBlockUserData::findPreviousBlockOpenParenthesis(&cursor), firstRun) { + firstRun = false; highlightBlocksInfo.open.prepend(cursor.blockNumber()); highlightBlocksInfo.visualIndent.prepend(d->visualIndent(cursor.block())); if (closeCursor.isNull()) diff --git a/src/plugins/texteditor/basetexteditor.h b/src/plugins/texteditor/basetexteditor.h index 7493fd34c89effdc161408e09a39ba55b3a4bcb0..e917696b57eee08f0651c602679ed91e4543bdeb 100644 --- a/src/plugins/texteditor/basetexteditor.h +++ b/src/plugins/texteditor/basetexteditor.h @@ -167,7 +167,7 @@ public: static bool findPreviousOpenParenthesis(QTextCursor *cursor, bool select = false); static bool findNextClosingParenthesis(QTextCursor *cursor, bool select = false); - static bool findPreviousBlockOpenParenthesis(QTextCursor *cursor); + static bool findPreviousBlockOpenParenthesis(QTextCursor *cursor, bool checkStartPosition = false); static bool findNextBlockClosingParenthesis(QTextCursor *cursor);