Highlight matching braces in decompiler view (#3285)

This commit is contained in:
Karthik Prakash 2024-01-27 22:08:34 +05:30 committed by GitHub
parent aabf442348
commit e3087e727a
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -7,6 +7,7 @@
#include <QColor> #include <QColor>
#include <QTextCursor> #include <QTextCursor>
#include <QPlainTextEdit> #include <QPlainTextEdit>
#include <QRegularExpression>
QList<QTextEdit::ExtraSelection> createSameWordsSelections(QPlainTextEdit *textEdit, QList<QTextEdit::ExtraSelection> createSameWordsSelections(QPlainTextEdit *textEdit,
const QString &word) const QString &word)
@ -21,6 +22,42 @@ QList<QTextEdit::ExtraSelection> createSameWordsSelections(QPlainTextEdit *textE
} }
highlightSelection.cursor = textEdit->textCursor(); 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); highlightSelection.cursor.movePosition(QTextCursor::Start, QTextCursor::MoveAnchor);
while (!highlightSelection.cursor.isNull() && !highlightSelection.cursor.atEnd()) { while (!highlightSelection.cursor.isNull() && !highlightSelection.cursor.atEnd()) {