diff --git a/src/plugins/cppeditor/cppeditor.cpp b/src/plugins/cppeditor/cppeditor.cpp index c36e78b40023aaf6bf418fa8b8f790fb45b64858..a6fbcfc03044ecfe0d5652f591fa01aee777087f 100644 --- a/src/plugins/cppeditor/cppeditor.cpp +++ b/src/plugins/cppeditor/cppeditor.cpp @@ -602,22 +602,6 @@ CPPEditor::Link CPPEditor::findLinkAt(const QTextCursor &cursor, if (!doc) return link; - // Handle include directives - const unsigned lineno = cursor.blockNumber() + 1; - foreach (const Document::Include &incl, doc->includes()) { - if (incl.line() == lineno && incl.resolved()) { - link.fileName = incl.fileName(); - link.pos = cursor.block().position(); - link.length = cursor.block().length(); - return link; - } - } - - // Find the last symbol up to the cursor position - Symbol *lastSymbol = doc->findSymbolAt(line, column); - if (!lastSymbol) - return link; - QTextCursor tc = cursor; static TokenUnderCursor tokenUnderCursor; @@ -625,9 +609,27 @@ CPPEditor::Link CPPEditor::findLinkAt(const QTextCursor &cursor, QTextBlock block; const SimpleToken tk = tokenUnderCursor(tc, &block); + // Handle include directives + if (tk.is(T_STRING_LITERAL) || tk.is(T_ANGLE_STRING_LITERAL)) { + const unsigned lineno = cursor.blockNumber() + 1; + foreach (const Document::Include &incl, doc->includes()) { + if (incl.line() == lineno && incl.resolved()) { + link.fileName = incl.fileName(); + link.pos = cursor.block().position() + tk.position() + 1; + link.length = tk.length() - 2; + return link; + } + } + } + if (tk.isNot(T_IDENTIFIER)) return link; + // Find the last symbol up to the cursor position + Symbol *lastSymbol = doc->findSymbolAt(line, column); + if (!lastSymbol) + return link; + const int nameStart = tk.position(); const int nameLength = tk.length(); const int endOfName = nameStart + nameLength;