Skip to content

Commit 71b4006

Browse files
committed
Highlight matching { when clicking on }
1 parent dd13583 commit 71b4006

File tree

1 file changed

+18
-5
lines changed

1 file changed

+18
-5
lines changed

src/common/SelectionHighlight.cpp

Lines changed: 18 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -23,14 +23,27 @@ QList<QTextEdit::ExtraSelection> createSameWordsSelections(QPlainTextEdit *textE
2323

2424
highlightSelection.cursor = textEdit->textCursor();
2525

26-
if (word == "{") {
26+
if (word == "{" || word == "}") {
27+
int val;
28+
if (word == "{") {
29+
val = 0;
30+
} else {
31+
val = 1;
32+
}
2733
selections.append(highlightSelection);
28-
int val = 0;
34+
2935
while (!highlightSelection.cursor.isNull() && !highlightSelection.cursor.atEnd()) {
30-
highlightSelection.cursor =
31-
document->find(QRegularExpression("{|}"), highlightSelection.cursor);
36+
if (word == "{") {
37+
highlightSelection.cursor =
38+
document->find(QRegularExpression("{|}"), highlightSelection.cursor);
39+
} else {
40+
highlightSelection.cursor =
41+
document->find(QRegularExpression("{|}"), highlightSelection.cursor,
42+
QTextDocument::FindBackward);
43+
}
44+
3245
if (!highlightSelection.cursor.isNull()) {
33-
if (highlightSelection.cursor.selectedText() == "{") {
46+
if (highlightSelection.cursor.selectedText() == word) {
3447
val++;
3548
} else {
3649
val--;

0 commit comments

Comments
 (0)