diff --git a/src/plugins/texteditor/basetexteditor.cpp b/src/plugins/texteditor/basetexteditor.cpp
index 55f6a2459f83eece8d64daa99f9f40c4e8e41ce3..0ee70102db2fed8da4ab8f4dde68854cde324c4b 100644
--- a/src/plugins/texteditor/basetexteditor.cpp
+++ b/src/plugins/texteditor/basetexteditor.cpp
@@ -1875,11 +1875,12 @@ void BaseTextEditorPrivate::highlightSearchResults(const QTextBlock &block,
     QString text = block.text();
     text.replace(QChar::Nbsp, QLatin1Char(' '));
     int idx = -1;
+    int l = 1;
     while (idx < text.length()) {
-        idx = m_searchExpr.indexIn(text, idx + 1);
+        idx = m_searchExpr.indexIn(text, idx + l);
         if (idx < 0)
             break;
-        int l = m_searchExpr.matchedLength();
+        l = m_searchExpr.matchedLength();
         if ((m_findFlags & Find::IFindSupport::FindWholeWords)
             && ((idx && text.at(idx-1).isLetterOrNumber())
                 || (idx + l < text.length() && text.at(idx + l).isLetterOrNumber())))