Skip to content

Commit

Permalink
NEW: JSRepl highlight search
Browse files Browse the repository at this point in the history
  • Loading branch information
altairwei committed Jul 31, 2023
1 parent bbe8d05 commit d985e95
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 2 deletions.
28 changes: 26 additions & 2 deletions src/jsplugin/JSRepl.cpp
Expand Up @@ -228,7 +228,11 @@ void JSReplSearchBox::findNext()
QTextCursor cursor = textEdit->textCursor();
cursor.movePosition(QTextCursor::Start);
textEdit->setTextCursor(cursor);
textEdit->find(text);
found = textEdit->find(text);
}

if (found) {
highlight(textEdit->textCursor());
}
}

Expand All @@ -241,11 +245,31 @@ void JSReplSearchBox::findPrevious()
QTextCursor cursor = textEdit->textCursor();
cursor.movePosition(QTextCursor::End);
textEdit->setTextCursor(cursor);
textEdit->find(text, QTextDocument::FindBackward);
found = textEdit->find(text, QTextDocument::FindBackward);
}

if (found) {
highlight(textEdit->textCursor());
}
}

void JSReplSearchBox::setFocusOnLineEdit()
{
lineEdit->setFocus();
}

void JSReplSearchBox::highlight(const QTextCursor &cursor)
{
QList<QTextEdit::ExtraSelection> extraSelections;

QTextEdit::ExtraSelection selection;
QColor lineColor = QColor(Qt::yellow).lighter(160);

selection.format.setBackground(lineColor);
selection.format.setProperty(QTextFormat::FullWidthSelection, true);
selection.cursor = cursor;
selection.cursor.clearSelection();
extraSelections.append(selection);

textEdit->setExtraSelections(extraSelections);
}
2 changes: 2 additions & 0 deletions src/jsplugin/JSRepl.h
Expand Up @@ -87,6 +87,8 @@ public slots:
void findPrevious();

private:
void highlight(const QTextCursor &cursor);

QTextEdit *textEdit;
QLineEdit *lineEdit;
};
Expand Down

0 comments on commit d985e95

Please sign in to comment.