diff options
author | Roberto Raggi <roberto.raggi@nokia.com> | 2010-08-17 13:41:45 +0200 |
---|---|---|
committer | Roberto Raggi <roberto.raggi@nokia.com> | 2010-08-17 13:42:30 +0200 |
commit | 5308a4a266a163b0e69729a550f844df67199890 (patch) | |
tree | 7963a83af48942dcc21a7b0c61c2a306fd903541 | |
parent | be9a3c94fa0d04d9adf840222e2306ad12f5db5c (diff) | |
download | qt-creator-5308a4a266a163b0e69729a550f844df67199890.tar.gz |
Fixed CppEditor::findLinkAt() to use the correct line and column positions from the editor.
-rw-r--r-- | src/plugins/cppeditor/cppeditor.cpp | 23 |
1 files changed, 14 insertions, 9 deletions
diff --git a/src/plugins/cppeditor/cppeditor.cpp b/src/plugins/cppeditor/cppeditor.cpp index 14a14bc24b..a995b5c39d 100644 --- a/src/plugins/cppeditor/cppeditor.cpp +++ b/src/plugins/cppeditor/cppeditor.cpp @@ -1071,11 +1071,11 @@ void CPPEditor::switchDeclarationDefinition() const Snapshot snapshot = m_modelManager->snapshot(); if (Document::Ptr thisDocument = snapshot.document(file()->fileName())) { - int line = 0, column = 0; - convertPosition(position(), &line, &column); + int line = 0, positionInBlock = 0; + convertPosition(position(), &line, &positionInBlock); - Scope *scope = thisDocument->scopeAt(line, column); - Symbol *lastVisibleSymbol = thisDocument->lastVisibleSymbolAt(line, column); + Scope *scope = thisDocument->scopeAt(line, positionInBlock + 1); + Symbol *lastVisibleSymbol = thisDocument->lastVisibleSymbolAt(line, positionInBlock + 1); Scope *functionScope = 0; if (scope->isFunction()) @@ -1159,12 +1159,15 @@ CPPEditor::Link CPPEditor::findLinkAt(const QTextCursor &cursor, return link; const Snapshot snapshot = m_modelManager->snapshot(); - int line = 0, column = 0; - convertPosition(cursor.position(), &line, &column); + int lineNumber = 0, positionInBlock = 0; + convertPosition(cursor.position(), &lineNumber, &positionInBlock); Document::Ptr doc = snapshot.document(file()->fileName()); if (!doc) return link; + const unsigned line = lineNumber; + const unsigned column = positionInBlock + 1; + QTextCursor tc = cursor; // Make sure we're not at the start of a word @@ -1188,7 +1191,7 @@ CPPEditor::Link CPPEditor::findLinkAt(const QTextCursor &cursor, for (int i = 0; i < tokens.size(); ++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) && (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, if (Symbol *d = r.declaration()) { if (d->isDeclaration() || d->isFunction()) { 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. break; } @@ -1286,9 +1289,11 @@ CPPEditor::Link CPPEditor::findLinkAt(const QTextCursor &cursor, Symbol *def = 0; if (resolveTarget) { + Symbol *lastVisibleSymbol = doc->lastVisibleSymbolAt(line, column); + def = findDefinition(symbol, snapshot); - if (def == doc->lastVisibleSymbolAt(line, column)) + if (def == lastVisibleSymbol) def = 0; // jump to declaration then. } |