aboutsummaryrefslogtreecommitdiffstats
path: root/src/plugins/texteditor
diff options
context:
space:
mode:
authorDavid Schulz <david.schulz@qt.io>2024-03-05 09:24:42 +0100
committerDavid Schulz <david.schulz@qt.io>2024-03-05 11:48:49 +0000
commit369105376008101ef710130bf17ebda84d24cbb7 (patch)
tree9b6ab3a9fc43e333753ef54a613699227166e127 /src/plugins/texteditor
parent568118af8b48b56fe567b8b8c19ff229f5a87e9e (diff)
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>
Diffstat (limited to 'src/plugins/texteditor')
-rw-r--r--src/plugins/texteditor/texteditor.cpp15
1 files changed, 11 insertions, 4 deletions
diff --git a/src/plugins/texteditor/texteditor.cpp b/src/plugins/texteditor/texteditor.cpp
index 054e65193f..3256ee91b7 100644
--- a/src/plugins/texteditor/texteditor.cpp
+++ b/src/plugins/texteditor/texteditor.cpp
@@ -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;