Fixed word highlighting in DisassemblyWidget (#2473)

* Fixed word highlighting in DisassemblyWidget
This commit is contained in:
xarkes 2020-11-15 21:26:49 +01:00 committed by GitHub
parent 5abc3427ee
commit 5d84844587
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -374,14 +374,26 @@ bool DisassemblyWidget::updateMaxLines()
void DisassemblyWidget::highlightCurrentLine() void DisassemblyWidget::highlightCurrentLine()
{ {
QList<QTextEdit::ExtraSelection> extraSelections; QList<QTextEdit::ExtraSelection> extraSelections;
QColor highlightColor = ConfigColor("lineHighlight"); QColor highlightColor = ConfigColor("lineHighlight");
// Highlight the current word // Highlight the current word
QTextCursor cursor = mDisasTextEdit->textCursor(); QTextCursor cursor = mDisasTextEdit->textCursor();
cursor.select(QTextCursor::WordUnderCursor); auto clickedCharPos = cursor.positionInBlock();
QString searchString = cursor.selectedText(); // Select the line (BlockUnderCursor matches a line with current implementation)
curHighlightedWord = searchString; 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 // Highlight the current line
QTextEdit::ExtraSelection highlightSelection; QTextEdit::ExtraSelection highlightSelection;