diff --git a/src/plugins/texteditor/texteditor.cpp b/src/plugins/texteditor/texteditor.cpp index 549d43a4a09..aa98df48632 100644 --- a/src/plugins/texteditor/texteditor.cpp +++ b/src/plugins/texteditor/texteditor.cpp @@ -836,8 +836,13 @@ public: int start; int length; }; - void addSearchResultsToScrollBar(const QVector &results); - void addSelectionHighlightToScrollBar(const QVector &selections); + void addSearchResultsToScrollBar( + const Id &category, + const QList &results, + Theme::Color color, + Highlight::Priority prio); + void addSearchResultsToScrollBar(const QList &results); + void addSelectionHighlightToScrollBar(const QList &selections); void adjustScrollBarRanges(); void setFindScope(const MultiTextCursor &scope); @@ -8211,7 +8216,11 @@ Highlight::Priority textMarkPrioToScrollBarPrio(const TextMark::Priority &prio) } } -void TextEditorWidgetPrivate::addSearchResultsToScrollBar(const QVector &results) +void TextEditorWidgetPrivate::addSearchResultsToScrollBar( + const Id &category, + const QList &results, + Theme::Color color, + Highlight::Priority prio) { if (!m_highlightScrollBarController) return; @@ -8223,45 +8232,33 @@ void TextEditorWidgetPrivate::addSearchResultsToScrollBar(const QVectorlineForTextPosition(result.start - block.position() + result.length).lineNumber(); for (int line = firstLine; line <= lastLine; ++line) { m_highlightScrollBarController->addHighlight( - {Constants::SCROLL_BAR_SEARCH_RESULT, block.firstLineNumber() + line, - Theme::TextEditor_SearchResult_ScrollBarColor, Highlight::HighPriority}); + {category, block.firstLineNumber() + line, color, prio}); } } else { m_highlightScrollBarController->addHighlight( - {Constants::SCROLL_BAR_SEARCH_RESULT, - block.blockNumber(), - Theme::TextEditor_SearchResult_ScrollBarColor, - Highlight::HighPriority}); + {category, block.blockNumber(), color, prio}); } } } } -void TextEditorWidgetPrivate::addSelectionHighlightToScrollBar( - const QVector &selections) +void TextEditorWidgetPrivate::addSearchResultsToScrollBar(const QList &results) { - if (!m_highlightScrollBarController) - return; - for (const SearchResult &result : selections) { - const QTextBlock &block = q->document()->findBlock(result.start); - if (block.isValid() && block.isVisible()) { - if (q->lineWrapMode() == QPlainTextEdit::WidgetWidth) { - const int firstLine = block.layout()->lineForTextPosition(result.start - block.position()).lineNumber(); - const int lastLine = block.layout()->lineForTextPosition(result.start - block.position() + result.length).lineNumber(); - for (int line = firstLine; line <= lastLine; ++line) { - m_highlightScrollBarController->addHighlight( - {Constants::SCROLL_BAR_SELECTION, block.firstLineNumber() + line, - Theme::TextEditor_Selection_ScrollBarColor, Highlight::NormalPriority}); - } - } else { - m_highlightScrollBarController->addHighlight( - {Constants::SCROLL_BAR_SELECTION, - block.blockNumber(), - Theme::TextEditor_Selection_ScrollBarColor, - Highlight::NormalPriority}); - } - } - } + addSearchResultsToScrollBar( + Constants::SCROLL_BAR_SEARCH_RESULT, + results, + Theme::TextEditor_SearchResult_ScrollBarColor, + Highlight::HighPriority); +} + +void TextEditorWidgetPrivate::addSelectionHighlightToScrollBar( + const QList &selections) +{ + addSearchResultsToScrollBar( + Constants::SCROLL_BAR_SELECTION, + selections, + Theme::TextEditor_Selection_ScrollBarColor, + Highlight::NormalPriority); } Highlight markToHighlight(TextMark *mark, int lineNumber)