Skip to content

Commit

Permalink
fix: [search] The background color position is incorrect
Browse files Browse the repository at this point in the history
as title

Log: fix issue
  • Loading branch information
Kakueeen committed Dec 3, 2024
1 parent 2091f3a commit 874660a
Showing 1 changed file with 11 additions and 1 deletion.
12 changes: 11 additions & 1 deletion src/plugins/find/gui/searchresultitemdelegate.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -402,6 +402,7 @@ void SearchResultItemDelegate::drawDisplay(QPainter *painter, const QStyleOption
painter->setPen(option.palette.color(QPalette::Normal, QPalette::Text));
}

// Remove leading spaces
QString displayText = text.trimmed();
if (displayText.isEmpty())
return;
Expand All @@ -420,7 +421,16 @@ void SearchResultItemDelegate::drawDisplay(QPainter *painter, const QStyleOption
textLayout.setTextOption(textOption);
textLayout.setFont(option.font);
textLayout.setText(displayText);
textLayout.setFormats(formatList.toVector());

// Adjust offsets in formatList
int offset = text.indexOf(displayText);
QList<QTextLayout::FormatRange> adjustedFormats = formatList;
if (offset != 0) {
for (auto &format : adjustedFormats) {
format.start -= offset;
}
}
textLayout.setFormats(adjustedFormats.toVector());

QSizeF textLayoutSize = doTextLayout(&textLayout, textRect.width());
if (textRect.width() < textLayoutSize.width()) {
Expand Down

0 comments on commit 874660a

Please sign in to comment.