Commit 5308a4a2 authored by Roberto Raggi's avatar Roberto Raggi

Fixed CppEditor::findLinkAt() to use the correct line and column positions from the editor.

parent be9a3c94
...@@ -1071,11 +1071,11 @@ void CPPEditor::switchDeclarationDefinition() ...@@ -1071,11 +1071,11 @@ void CPPEditor::switchDeclarationDefinition()
const Snapshot snapshot = m_modelManager->snapshot(); const Snapshot snapshot = m_modelManager->snapshot();
if (Document::Ptr thisDocument = snapshot.document(file()->fileName())) { if (Document::Ptr thisDocument = snapshot.document(file()->fileName())) {
int line = 0, column = 0; int line = 0, positionInBlock = 0;
convertPosition(position(), &line, &column); convertPosition(position(), &line, &positionInBlock);
Scope *scope = thisDocument->scopeAt(line, column); Scope *scope = thisDocument->scopeAt(line, positionInBlock + 1);
Symbol *lastVisibleSymbol = thisDocument->lastVisibleSymbolAt(line, column); Symbol *lastVisibleSymbol = thisDocument->lastVisibleSymbolAt(line, positionInBlock + 1);
Scope *functionScope = 0; Scope *functionScope = 0;
if (scope->isFunction()) if (scope->isFunction())
...@@ -1159,12 +1159,15 @@ CPPEditor::Link CPPEditor::findLinkAt(const QTextCursor &cursor, ...@@ -1159,12 +1159,15 @@ CPPEditor::Link CPPEditor::findLinkAt(const QTextCursor &cursor,
return link; return link;
const Snapshot snapshot = m_modelManager->snapshot(); const Snapshot snapshot = m_modelManager->snapshot();
int line = 0, column = 0; int lineNumber = 0, positionInBlock = 0;
convertPosition(cursor.position(), &line, &column); convertPosition(cursor.position(), &lineNumber, &positionInBlock);
Document::Ptr doc = snapshot.document(file()->fileName()); Document::Ptr doc = snapshot.document(file()->fileName());
if (!doc) if (!doc)
return link; return link;
const unsigned line = lineNumber;
const unsigned column = positionInBlock + 1;
QTextCursor tc = cursor; QTextCursor tc = cursor;
// Make sure we're not at the start of a word // Make sure we're not at the start of a word
...@@ -1188,7 +1191,7 @@ CPPEditor::Link CPPEditor::findLinkAt(const QTextCursor &cursor, ...@@ -1188,7 +1191,7 @@ CPPEditor::Link CPPEditor::findLinkAt(const QTextCursor &cursor,
for (int i = 0; i < tokens.size(); ++i) { for (int i = 0; i < tokens.size(); ++i) {
const Token &tk = tokens.at(i); const Token &tk = tokens.at(i);
if (((unsigned) column) >= tk.begin() && ((unsigned) column) <= tk.end()) { if (((unsigned) positionInBlock) >= tk.begin() && ((unsigned) positionInBlock) <= tk.end()) {
if (i >= 2 && tokens.at(i).is(T_IDENTIFIER) && tokens.at(i - 1).is(T_LPAREN) if (i >= 2 && tokens.at(i).is(T_IDENTIFIER) && tokens.at(i - 1).is(T_LPAREN)
&& (tokens.at(i - 2).is(T_SIGNAL) || tokens.at(i - 2).is(T_SLOT))) { && (tokens.at(i - 2).is(T_SIGNAL) || tokens.at(i - 2).is(T_SLOT))) {
...@@ -1273,7 +1276,7 @@ CPPEditor::Link CPPEditor::findLinkAt(const QTextCursor &cursor, ...@@ -1273,7 +1276,7 @@ CPPEditor::Link CPPEditor::findLinkAt(const QTextCursor &cursor,
if (Symbol *d = r.declaration()) { if (Symbol *d = r.declaration()) {
if (d->isDeclaration() || d->isFunction()) { if (d->isDeclaration() || d->isFunction()) {
if (file()->fileName() == QString::fromUtf8(d->fileName(), d->fileNameLength())) { if (file()->fileName() == QString::fromUtf8(d->fileName(), d->fileNameLength())) {
if (unsigned(line) == d->line() && unsigned(column) >= d->column()) { // ### TODO: check the end if (unsigned(lineNumber) == d->line() && unsigned(positionInBlock) >= d->column()) { // ### TODO: check the end
result = r; // take the symbol under cursor. result = r; // take the symbol under cursor.
break; break;
} }
...@@ -1286,9 +1289,11 @@ CPPEditor::Link CPPEditor::findLinkAt(const QTextCursor &cursor, ...@@ -1286,9 +1289,11 @@ CPPEditor::Link CPPEditor::findLinkAt(const QTextCursor &cursor,
Symbol *def = 0; Symbol *def = 0;
if (resolveTarget) { if (resolveTarget) {
Symbol *lastVisibleSymbol = doc->lastVisibleSymbolAt(line, column);
def = findDefinition(symbol, snapshot); def = findDefinition(symbol, snapshot);
if (def == doc->lastVisibleSymbolAt(line, column)) if (def == lastVisibleSymbol)
def = 0; // jump to declaration then. def = 0; // jump to declaration then.
} }
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment