mirror of
https://github.com/rizinorg/cutter.git
synced 2024-12-18 10:56:11 +00:00
Fixed word highlighting in DisassemblyWidget (#2473)
* Fixed word highlighting in DisassemblyWidget
This commit is contained in:
parent
5abc3427ee
commit
5d84844587
@ -374,14 +374,26 @@ bool DisassemblyWidget::updateMaxLines()
|
||||
void DisassemblyWidget::highlightCurrentLine()
|
||||
{
|
||||
QList<QTextEdit::ExtraSelection> extraSelections;
|
||||
|
||||
QColor highlightColor = ConfigColor("lineHighlight");
|
||||
|
||||
// Highlight the current word
|
||||
QTextCursor cursor = mDisasTextEdit->textCursor();
|
||||
cursor.select(QTextCursor::WordUnderCursor);
|
||||
QString searchString = cursor.selectedText();
|
||||
curHighlightedWord = searchString;
|
||||
auto clickedCharPos = cursor.positionInBlock();
|
||||
// Select the line (BlockUnderCursor matches a line with current implementation)
|
||||
cursor.select(QTextCursor::BlockUnderCursor);
|
||||
// Remove any non-breakable space from the current line
|
||||
QString searchString = cursor.selectedText().replace("\xc2\xa0", " ");
|
||||
// Cut the line in "tokens" that can be highlighted
|
||||
static const QRegularExpression tokenRegExp(R"(\b(?<!\.)([^\s]+)\b(?!\.))");
|
||||
QRegularExpressionMatchIterator i = tokenRegExp.globalMatch(searchString);
|
||||
while (i.hasNext()) {
|
||||
QRegularExpressionMatch match = i.next();
|
||||
// Current token is under our cursor, select this one
|
||||
if (match.capturedStart() <= clickedCharPos && match.capturedEnd() > clickedCharPos) {
|
||||
curHighlightedWord = match.captured();
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
// Highlight the current line
|
||||
QTextEdit::ExtraSelection highlightSelection;
|
||||
|
Loading…
Reference in New Issue
Block a user