Skip to content

Commit

Permalink
Highlight matching { when clicking on }
Browse files Browse the repository at this point in the history
  • Loading branch information
skoriop committed Jan 24, 2024
1 parent dd13583 commit 71b4006
Showing 1 changed file with 18 additions and 5 deletions.
23 changes: 18 additions & 5 deletions src/common/SelectionHighlight.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,14 +23,27 @@ QList<QTextEdit::ExtraSelection> createSameWordsSelections(QPlainTextEdit *textE

highlightSelection.cursor = textEdit->textCursor();

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

while (!highlightSelection.cursor.isNull() && !highlightSelection.cursor.atEnd()) {
highlightSelection.cursor =
document->find(QRegularExpression("{|}"), highlightSelection.cursor);
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() == "{") {
if (highlightSelection.cursor.selectedText() == word) {
val++;
} else {
val--;
Expand Down

0 comments on commit 71b4006

Please sign in to comment.