diff --git a/src/plugins/qmljseditor/qmljseditor.cpp b/src/plugins/qmljseditor/qmljseditor.cpp
index 924c45d3513f129d9ba4fdf9011b433b69c9ad91..021643535fc060a3ff4682ca808d6bafa201eec2 100644
--- a/src/plugins/qmljseditor/qmljseditor.cpp
+++ b/src/plugins/qmljseditor/qmljseditor.cpp
@@ -1122,10 +1122,15 @@ static void appendExtraSelectionsForMessages(
         sel.cursor = c;
 
         sel.cursor.setPosition(c.position() + column - 1);
-        if (sel.cursor.atBlockEnd())
-            sel.cursor.movePosition(QTextCursor::StartOfWord, QTextCursor::KeepAnchor);
-        else
-            sel.cursor.movePosition(QTextCursor::EndOfWord, QTextCursor::KeepAnchor);
+
+        if (d.loc.length == 0) {
+            if (sel.cursor.atBlockEnd())
+                sel.cursor.movePosition(QTextCursor::StartOfWord, QTextCursor::KeepAnchor);
+            else
+                sel.cursor.movePosition(QTextCursor::EndOfWord, QTextCursor::KeepAnchor);
+        } else {
+            sel.cursor.movePosition(QTextCursor::NextCharacter, QTextCursor::KeepAnchor, d.loc.length);
+        }
 
         if (d.isWarning())
             sel.format.setUnderlineColor(Qt::darkYellow);