forked from qt-creator/qt-creator
TextEditor: fix finding whole words
'_' was handled as a word separator, in contrast the global search did not. So the user received different results when using find toolbar or the advanced search while searching with the same option and pattern. Fixes: QTCREATORBUG-10276 Change-Id: Ie07303fbaa35475bb98bdb813358169474c3ba1d Reviewed-by: Marcus Tillmanns <marcus.tillmanns@qt.io>
This commit is contained in:
@@ -4154,10 +4154,17 @@ void TextEditorWidgetPrivate::highlightSearchResults(const QTextBlock &block, co
|
||||
l = match.capturedLength();
|
||||
if (l == 0)
|
||||
break;
|
||||
if ((m_findFlags & FindWholeWords)
|
||||
&& ((idx && text.at(idx-1).isLetterOrNumber())
|
||||
|| (idx + l < text.length() && text.at(idx + l).isLetterOrNumber())))
|
||||
continue;
|
||||
if (m_findFlags & FindWholeWords) {
|
||||
auto posAtWordSeparator = [](const QString &text, int idx) {
|
||||
if (idx < 0 || idx >= text.length())
|
||||
return false;
|
||||
const QChar c = text.at(idx);
|
||||
return !c.isLetterOrNumber() && c != QLatin1Char('_');
|
||||
};
|
||||
if (!posAtWordSeparator(text, idx - 1) || !posAtWordSeparator(text, idx + l))
|
||||
continue;
|
||||
}
|
||||
|
||||
|
||||
const int start = blockPosition + idx;
|
||||
const int end = start + l;
|
||||
|
Reference in New Issue
Block a user