mirror of
https://github.com/rizinorg/cutter.git
synced 2024-12-18 19:06:10 +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()
|
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;
|
||||||
|
Loading…
Reference in New Issue
Block a user