Commit b9e376f5 authored by mae's avatar mae
Browse files

fix block highlighting off-by-one

parent 13c699e2
......@@ -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())
......
......@@ -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);
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment