Skip to content

Commit

Permalink
Highlight matching braces in decompiler view (#3285)
Browse files Browse the repository at this point in the history
  • Loading branch information
skoriop authored Jan 27, 2024
1 parent aabf442 commit e3087e7
Showing 1 changed file with 37 additions and 0 deletions.
37 changes: 37 additions & 0 deletions src/common/SelectionHighlight.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
#include <QColor>
#include <QTextCursor>
#include <QPlainTextEdit>
#include <QRegularExpression>

QList<QTextEdit::ExtraSelection> createSameWordsSelections(QPlainTextEdit *textEdit,
const QString &word)
Expand All @@ -21,6 +22,42 @@ QList<QTextEdit::ExtraSelection> createSameWordsSelections(QPlainTextEdit *textE
}

highlightSelection.cursor = textEdit->textCursor();

if (word == "{" || word == "}") {
int val;
if (word == "{") {
val = 0;
} else {
val = 1;
}
selections.append(highlightSelection);

while (!highlightSelection.cursor.isNull() && !highlightSelection.cursor.atEnd()) {
if (word == "{") {
highlightSelection.cursor =
document->find(QRegularExpression("{|}"), highlightSelection.cursor);
} else {
highlightSelection.cursor =
document->find(QRegularExpression("{|}"), highlightSelection.cursor,
QTextDocument::FindBackward);
}

if (!highlightSelection.cursor.isNull()) {
if (highlightSelection.cursor.selectedText() == word) {
val++;
} else {
val--;
}
if (val == 0) {
highlightSelection.format.setBackground(highlightWordColor);
selections.append(highlightSelection);
break;
}
}
}
return selections;
}

highlightSelection.cursor.movePosition(QTextCursor::Start, QTextCursor::MoveAnchor);

while (!highlightSelection.cursor.isNull() && !highlightSelection.cursor.atEnd()) {
Expand Down

0 comments on commit e3087e7

Please sign in to comment.