From 369105376008101ef710130bf17ebda84d24cbb7 Mon Sep 17 00:00:00 2001 From: David Schulz Date: Tue, 5 Mar 2024 09:24:42 +0100 Subject: [PATCH] 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 --- src/plugins/texteditor/texteditor.cpp | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/src/plugins/texteditor/texteditor.cpp b/src/plugins/texteditor/texteditor.cpp index 054e65193f4..3256ee91b79 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;