forked from qt-creator/qt-creator
Only highlight the filename of an include as link
Previously the whole line turned into a link. I think it looks a bit nicer now.
This commit is contained in:
@@ -602,22 +602,6 @@ CPPEditor::Link CPPEditor::findLinkAt(const QTextCursor &cursor,
|
|||||||
if (!doc)
|
if (!doc)
|
||||||
return link;
|
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;
|
QTextCursor tc = cursor;
|
||||||
|
|
||||||
static TokenUnderCursor tokenUnderCursor;
|
static TokenUnderCursor tokenUnderCursor;
|
||||||
@@ -625,9 +609,27 @@ CPPEditor::Link CPPEditor::findLinkAt(const QTextCursor &cursor,
|
|||||||
QTextBlock block;
|
QTextBlock block;
|
||||||
const SimpleToken tk = tokenUnderCursor(tc, &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))
|
if (tk.isNot(T_IDENTIFIER))
|
||||||
return link;
|
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 nameStart = tk.position();
|
||||||
const int nameLength = tk.length();
|
const int nameLength = tk.length();
|
||||||
const int endOfName = nameStart + nameLength;
|
const int endOfName = nameStart + nameLength;
|
||||||
|
|||||||
Reference in New Issue
Block a user