TextEditor: fix highlighting whole words matches

... at line start and end.

Fixes: QTCREATORBUG-31020
Change-Id: I3b26089ef72a34dedfe8846119f672e75bf03215
Reviewed-by: Christian Stenger <christian.stenger@qt.io>
This commit is contained in:
David Schulz
2024-07-10 14:13:56 +02:00
parent 60b0d88df9
commit 6988462cd5

View File

@@ -4754,8 +4754,11 @@ void TextEditorWidgetPrivate::highlightSearchResults(const QTextBlock &block, co
break; break;
if (m_findFlags & FindWholeWords) { if (m_findFlags & FindWholeWords) {
auto posAtWordSeparator = [](const QString &text, int idx) { auto posAtWordSeparator = [](const QString &text, int idx) {
if (idx < 0 || idx >= text.length()) if (idx < 0)
return false; return QTC_GUARD(idx == -1);
int textLength = text.length();
if (idx >= textLength)
return QTC_GUARD(idx == textLength);
const QChar c = text.at(idx); const QChar c = text.at(idx);
return !c.isLetterOrNumber() && c != QLatin1Char('_'); return !c.isLetterOrNumber() && c != QLatin1Char('_');
}; };