forked from qt-creator/qt-creator
Utils: Adjust column numbers affected by convertPosition change
convertPosition change was introduced in 931ec39f64.
It changed 0-based column to 1-based which is how it
naturally is in Qt Creator.
This fixed some usages but broke many more. This is an
attempt to fix the remaining use cases.
Fixes CppEditor auto-tests.
Change-Id: Ia8d14da0ebb035cd2fdd6da4ff6ec89c1c5121a8
Reviewed-by: Nikolai Kosjar <nikolai.kosjar@qt.io>
This commit is contained in:
@@ -163,13 +163,10 @@ void ClangFollowSymbol::findLink(const CppTools::CursorInEditor &data,
|
|||||||
CppTools::SymbolFinder *symbolFinder,
|
CppTools::SymbolFinder *symbolFinder,
|
||||||
bool inNextSplit)
|
bool inNextSplit)
|
||||||
{
|
{
|
||||||
int lineNumber = 0, positionInBlock = 0;
|
int line = 0;
|
||||||
|
int column = 0;
|
||||||
QTextCursor cursor = Utils::Text::wordStartCursor(data.cursor());
|
QTextCursor cursor = Utils::Text::wordStartCursor(data.cursor());
|
||||||
Utils::Text::convertPosition(cursor.document(), cursor.position(), &lineNumber,
|
Utils::Text::convertPosition(cursor.document(), cursor.position(), &line, &column);
|
||||||
&positionInBlock);
|
|
||||||
|
|
||||||
const uint line = lineNumber;
|
|
||||||
const uint column = positionInBlock + 1;
|
|
||||||
|
|
||||||
ClangEditorDocumentProcessor *processor = ClangEditorDocumentProcessor::get(
|
ClangEditorDocumentProcessor *processor = ClangEditorDocumentProcessor::get(
|
||||||
data.filePath().toString());
|
data.filePath().toString());
|
||||||
@@ -177,7 +174,10 @@ void ClangFollowSymbol::findLink(const CppTools::CursorInEditor &data,
|
|||||||
return processLinkCallback(Utils::Link());
|
return processLinkCallback(Utils::Link());
|
||||||
|
|
||||||
if (!resolveTarget) {
|
if (!resolveTarget) {
|
||||||
processLinkCallback(linkAtCursor(cursor, data.filePath().toString(), line, column,
|
processLinkCallback(linkAtCursor(cursor,
|
||||||
|
data.filePath().toString(),
|
||||||
|
static_cast<uint>(line),
|
||||||
|
static_cast<uint>(column),
|
||||||
processor));
|
processor));
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -423,7 +423,7 @@ void Manager::onDocumentUpdated(CPlusPlus::Document::Ptr doc)
|
|||||||
|
|
||||||
/*!
|
/*!
|
||||||
Opens the text editor for the file \a fileName on \a line (1-based) and
|
Opens the text editor for the file \a fileName on \a line (1-based) and
|
||||||
\a column (1-based).
|
\a column (0-based).
|
||||||
*/
|
*/
|
||||||
|
|
||||||
void Manager::gotoLocation(const QString &fileName, int line, int column)
|
void Manager::gotoLocation(const QString &fileName, int line, int column)
|
||||||
@@ -468,7 +468,8 @@ void Manager::gotoLocations(const QList<QVariant> &list)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
gotoLocation(loc.fileName(), loc.line(), loc.column());
|
// line is 1-based, column is 0-based
|
||||||
|
gotoLocation(loc.fileName(), loc.line(), loc.column() - 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
/*!
|
/*!
|
||||||
|
|||||||
@@ -369,9 +369,9 @@ void Parser::addSymbol(const ParserTreeItem::Ptr &item, const CPlusPlus::Symbol
|
|||||||
if (itemAdd.isNull())
|
if (itemAdd.isNull())
|
||||||
itemAdd = ParserTreeItem::Ptr(new ParserTreeItem());
|
itemAdd = ParserTreeItem::Ptr(new ParserTreeItem());
|
||||||
|
|
||||||
// locations are 1-based in Symbol, start with 0 for the editor
|
// locations have 1-based column in Symbol, use the same here.
|
||||||
SymbolLocation location(QString::fromUtf8(symbol->fileName() , symbol->fileNameLength()),
|
SymbolLocation location(QString::fromUtf8(symbol->fileName() , symbol->fileNameLength()),
|
||||||
symbol->line(), symbol->column() - 1);
|
symbol->line(), symbol->column());
|
||||||
itemAdd->addSymbolLocation(location);
|
itemAdd->addSymbolLocation(location);
|
||||||
|
|
||||||
// prevent showing a content of the functions
|
// prevent showing a content of the functions
|
||||||
|
|||||||
@@ -146,8 +146,10 @@ void CMakeEditorWidget::findLinkAt(const QTextCursor &cursor,
|
|||||||
{
|
{
|
||||||
Utils::Link link;
|
Utils::Link link;
|
||||||
|
|
||||||
int lineNumber = 0, positionInBlock = 0;
|
int line = 0;
|
||||||
convertPosition(cursor.position(), &lineNumber, &positionInBlock);
|
int column = 0;
|
||||||
|
convertPosition(cursor.position(), &line, &column);
|
||||||
|
const int positionInBlock = column - 1;
|
||||||
|
|
||||||
const QString block = cursor.block().text();
|
const QString block = cursor.block().text();
|
||||||
|
|
||||||
|
|||||||
@@ -31,6 +31,7 @@
|
|||||||
#include <QElapsedTimer>
|
#include <QElapsedTimer>
|
||||||
#include <QtTest>
|
#include <QtTest>
|
||||||
|
|
||||||
|
// Uses 1-based line and 0-based column.
|
||||||
struct Selection {
|
struct Selection {
|
||||||
Selection(int line, int column, int length) : line(line), column(column), length(length) {}
|
Selection(int line, int column, int length) : line(line), column(column), length(length) {}
|
||||||
int line;
|
int line;
|
||||||
@@ -116,7 +117,7 @@ SelectionList UseSelectionsTestCase::toSelectionList(
|
|||||||
int line, column;
|
int line, column;
|
||||||
const int position = qMin(selection.cursor.position(), selection.cursor.anchor());
|
const int position = qMin(selection.cursor.position(), selection.cursor.anchor());
|
||||||
m_editorWidget->convertPosition(position, &line, &column);
|
m_editorWidget->convertPosition(position, &line, &column);
|
||||||
result << Selection(line, column, selection.cursor.selectedText().length());
|
result << Selection(line, column - 1, selection.cursor.selectedText().length());
|
||||||
}
|
}
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -317,7 +317,7 @@ F2TestCase::F2TestCase(CppEditorAction action,
|
|||||||
|
|
||||||
initialTestFile->m_editor->setCursorPosition(initialTestFile->m_cursorPosition);
|
initialTestFile->m_editor->setCursorPosition(initialTestFile->m_cursorPosition);
|
||||||
// qDebug() << "Initial line:" << initialTestFile->editor->currentLine();
|
// qDebug() << "Initial line:" << initialTestFile->editor->currentLine();
|
||||||
// qDebug() << "Initial column:" << initialTestFile->editor->currentColumn() - 1;
|
// qDebug() << "Initial column:" << initialTestFile->editor->currentColumn();
|
||||||
|
|
||||||
OverrideItemList immediateVirtualSymbolResults;
|
OverrideItemList immediateVirtualSymbolResults;
|
||||||
OverrideItemList finalVirtualSymbolResults;
|
OverrideItemList finalVirtualSymbolResults;
|
||||||
@@ -338,7 +338,7 @@ F2TestCase::F2TestCase(CppEditorAction action,
|
|||||||
QSKIP((curTestName + " is not supported by Clang FollowSymbol").toLatin1());
|
QSKIP((curTestName + " is not supported by Clang FollowSymbol").toLatin1());
|
||||||
}
|
}
|
||||||
|
|
||||||
initialTestFile->m_editorWidget->openLinkUnderCursor();
|
widget->openLinkUnderCursor();
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -349,7 +349,7 @@ F2TestCase::F2TestCase(CppEditorAction action,
|
|||||||
QSharedPointer<VirtualFunctionTestAssistProvider> testProvider(
|
QSharedPointer<VirtualFunctionTestAssistProvider> testProvider(
|
||||||
new VirtualFunctionTestAssistProvider(widget));
|
new VirtualFunctionTestAssistProvider(widget));
|
||||||
builtinFollowSymbol->setVirtualFunctionAssistProvider(testProvider);
|
builtinFollowSymbol->setVirtualFunctionAssistProvider(testProvider);
|
||||||
initialTestFile->m_editorWidget->openLinkUnderCursor();
|
widget->openLinkUnderCursor();
|
||||||
immediateVirtualSymbolResults = testProvider->m_immediateItems;
|
immediateVirtualSymbolResults = testProvider->m_immediateItems;
|
||||||
finalVirtualSymbolResults = testProvider->m_finalItems;
|
finalVirtualSymbolResults = testProvider->m_finalItems;
|
||||||
|
|
||||||
@@ -382,7 +382,7 @@ F2TestCase::F2TestCase(CppEditorAction action,
|
|||||||
QEXPECT_FAIL("globalVarFromEnum", "Contributor works on a fix.", Abort);
|
QEXPECT_FAIL("globalVarFromEnum", "Contributor works on a fix.", Abort);
|
||||||
QEXPECT_FAIL("matchFunctionSignature_Follow_5", "foo(int) resolved as CallAST", Abort);
|
QEXPECT_FAIL("matchFunctionSignature_Follow_5", "foo(int) resolved as CallAST", Abort);
|
||||||
QCOMPARE(currentTextEditor->currentLine(), expectedLine);
|
QCOMPARE(currentTextEditor->currentLine(), expectedLine);
|
||||||
QCOMPARE(currentTextEditor->currentColumn() - 1, expectedColumn);
|
QCOMPARE(currentTextEditor->currentColumn(), expectedColumn);
|
||||||
|
|
||||||
// qDebug() << immediateVirtualSymbolResults;
|
// qDebug() << immediateVirtualSymbolResults;
|
||||||
// qDebug() << finalVirtualSymbolResults;
|
// qDebug() << finalVirtualSymbolResults;
|
||||||
|
|||||||
@@ -184,8 +184,9 @@ private:
|
|||||||
{
|
{
|
||||||
CursorInfo result;
|
CursorInfo result;
|
||||||
|
|
||||||
|
// findLocalUses operates with 1-based line and 0-based column
|
||||||
const CppTools::SemanticInfo::LocalUseMap localUses
|
const CppTools::SemanticInfo::LocalUseMap localUses
|
||||||
= BuiltinCursorInfo::findLocalUses(m_document, m_line, m_column);
|
= BuiltinCursorInfo::findLocalUses(m_document, m_line, m_column - 1);
|
||||||
result.localUses = localUses;
|
result.localUses = localUses;
|
||||||
splitLocalUses(localUses, &result.useRanges, &result.unusedVariablesRanges);
|
splitLocalUses(localUses, &result.useRanges, &result.unusedVariablesRanges);
|
||||||
|
|
||||||
@@ -216,8 +217,7 @@ private:
|
|||||||
bool good = false;
|
bool good = false;
|
||||||
foreach (const CppTools::SemanticInfo::Use &use, uses) {
|
foreach (const CppTools::SemanticInfo::Use &use, uses) {
|
||||||
unsigned l = static_cast<unsigned>(m_line);
|
unsigned l = static_cast<unsigned>(m_line);
|
||||||
// convertCursorPosition() returns a 0-based column number.
|
unsigned c = static_cast<unsigned>(m_column);
|
||||||
unsigned c = static_cast<unsigned>(m_column + 1);
|
|
||||||
if (l == use.line && c >= use.column && c <= (use.column + use.length)) {
|
if (l == use.line && c >= use.column && c <= (use.column + use.length)) {
|
||||||
good = true;
|
good = true;
|
||||||
break;
|
break;
|
||||||
|
|||||||
@@ -112,7 +112,6 @@ CppTools::CheckSymbols *createHighlighter(const CPlusPlus::Document::Ptr &doc,
|
|||||||
int line, column;
|
int line, column;
|
||||||
convertPosition(textDocument, macro.utf16CharOffset(), &line, &column);
|
convertPosition(textDocument, macro.utf16CharOffset(), &line, &column);
|
||||||
|
|
||||||
++column; //Highlighting starts at (column-1) --> compensate here
|
|
||||||
Result use(line, column, macro.nameToQString().size(), SemanticHighlighter::MacroUse);
|
Result use(line, column, macro.nameToQString().size(), SemanticHighlighter::MacroUse);
|
||||||
macroUses.append(use);
|
macroUses.append(use);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -60,7 +60,6 @@ Scope *CanonicalSymbol::getScopeAndExpression(const QTextCursor &cursor, QString
|
|||||||
QTextCursor tc = cursor;
|
QTextCursor tc = cursor;
|
||||||
int line, column;
|
int line, column;
|
||||||
Utils::Text::convertPosition(cursor.document(), tc.position(), &line, &column);
|
Utils::Text::convertPosition(cursor.document(), tc.position(), &line, &column);
|
||||||
++column; // 1-based line and 1-based column
|
|
||||||
|
|
||||||
int pos = tc.position();
|
int pos = tc.position();
|
||||||
QTextDocument *textDocument = cursor.document();
|
QTextDocument *textDocument = cursor.document();
|
||||||
@@ -74,7 +73,7 @@ Scope *CanonicalSymbol::getScopeAndExpression(const QTextCursor &cursor, QString
|
|||||||
|
|
||||||
ExpressionUnderCursor expressionUnderCursor(m_document->languageFeatures());
|
ExpressionUnderCursor expressionUnderCursor(m_document->languageFeatures());
|
||||||
*code = expressionUnderCursor(tc);
|
*code = expressionUnderCursor(tc);
|
||||||
return m_document->scopeAt(line, column);
|
return m_document->scopeAt(line, column - 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
Symbol *CanonicalSymbol::operator()(const QTextCursor &cursor)
|
Symbol *CanonicalSymbol::operator()(const QTextCursor &cursor)
|
||||||
|
|||||||
@@ -1092,7 +1092,7 @@ int InternalCppCompletionAssistProcessor::startCompletionHelper()
|
|||||||
int line = 0, column = 0;
|
int line = 0, column = 0;
|
||||||
Utils::Text::convertPosition(m_interface->textDocument(), startOfExpression, &line, &column);
|
Utils::Text::convertPosition(m_interface->textDocument(), startOfExpression, &line, &column);
|
||||||
const QString fileName = m_interface->fileName();
|
const QString fileName = m_interface->fileName();
|
||||||
return startCompletionInternal(fileName, line, column, expression, endOfExpression);
|
return startCompletionInternal(fileName, line, column - 1, expression, endOfExpression);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool InternalCppCompletionAssistProcessor::tryObjCCompletion()
|
bool InternalCppCompletionAssistProcessor::tryObjCCompletion()
|
||||||
@@ -1125,7 +1125,7 @@ bool InternalCppCompletionAssistProcessor::tryObjCCompletion()
|
|||||||
int line = 0, column = 0;
|
int line = 0, column = 0;
|
||||||
Utils::Text::convertPosition(m_interface->textDocument(), m_interface->position(), &line,
|
Utils::Text::convertPosition(m_interface->textDocument(), m_interface->position(), &line,
|
||||||
&column);
|
&column);
|
||||||
Scope *scope = thisDocument->scopeAt(line, column);
|
Scope *scope = thisDocument->scopeAt(line, column - 1);
|
||||||
if (!scope)
|
if (!scope)
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
@@ -1319,7 +1319,8 @@ bool InternalCppCompletionAssistProcessor::objcKeywordsWanted() const
|
|||||||
}
|
}
|
||||||
|
|
||||||
int InternalCppCompletionAssistProcessor::startCompletionInternal(const QString &fileName,
|
int InternalCppCompletionAssistProcessor::startCompletionInternal(const QString &fileName,
|
||||||
unsigned line, unsigned column,
|
unsigned line,
|
||||||
|
unsigned positionInBlock,
|
||||||
const QString &expr,
|
const QString &expr,
|
||||||
int endOfExpression)
|
int endOfExpression)
|
||||||
{
|
{
|
||||||
@@ -1331,7 +1332,7 @@ int InternalCppCompletionAssistProcessor::startCompletionInternal(const QString
|
|||||||
|
|
||||||
m_model->m_typeOfExpression->init(thisDocument, m_interface->snapshot());
|
m_model->m_typeOfExpression->init(thisDocument, m_interface->snapshot());
|
||||||
|
|
||||||
Scope *scope = thisDocument->scopeAt(line, column);
|
Scope *scope = thisDocument->scopeAt(line, positionInBlock);
|
||||||
QTC_ASSERT(scope != 0, return -1);
|
QTC_ASSERT(scope != 0, return -1);
|
||||||
|
|
||||||
if (expression.isEmpty()) {
|
if (expression.isEmpty()) {
|
||||||
@@ -2016,7 +2017,7 @@ bool InternalCppCompletionAssistProcessor::completeConstructorOrFunction(const Q
|
|||||||
int lineSigned = 0, columnSigned = 0;
|
int lineSigned = 0, columnSigned = 0;
|
||||||
Utils::Text::convertPosition(m_interface->textDocument(), m_interface->position(),
|
Utils::Text::convertPosition(m_interface->textDocument(), m_interface->position(),
|
||||||
&lineSigned, &columnSigned);
|
&lineSigned, &columnSigned);
|
||||||
unsigned line = lineSigned, column = columnSigned;
|
unsigned line = lineSigned, column = columnSigned - 1;
|
||||||
|
|
||||||
// find a scope that encloses the current location, starting from the lastVisibileSymbol
|
// find a scope that encloses the current location, starting from the lastVisibileSymbol
|
||||||
// and moving outwards
|
// and moving outwards
|
||||||
|
|||||||
@@ -113,7 +113,7 @@ private:
|
|||||||
bool tryObjCCompletion();
|
bool tryObjCCompletion();
|
||||||
bool objcKeywordsWanted() const;
|
bool objcKeywordsWanted() const;
|
||||||
int startCompletionInternal(const QString &fileName,
|
int startCompletionInternal(const QString &fileName,
|
||||||
unsigned line, unsigned column,
|
unsigned line, unsigned positionInBlock,
|
||||||
const QString &expression,
|
const QString &expression,
|
||||||
int endOfExpression);
|
int endOfExpression);
|
||||||
|
|
||||||
|
|||||||
@@ -373,7 +373,7 @@ void CppElementEvaluator::execute()
|
|||||||
// Fetch the expression's code
|
// Fetch the expression's code
|
||||||
ExpressionUnderCursor expressionUnderCursor(doc->languageFeatures());
|
ExpressionUnderCursor expressionUnderCursor(doc->languageFeatures());
|
||||||
const QString &expression = expressionUnderCursor(m_tc);
|
const QString &expression = expressionUnderCursor(m_tc);
|
||||||
Scope *scope = doc->scopeAt(line, column);
|
Scope *scope = doc->scopeAt(line, column - 1);
|
||||||
|
|
||||||
TypeOfExpression typeOfExpression;
|
TypeOfExpression typeOfExpression;
|
||||||
typeOfExpression.init(doc, snapshot);
|
typeOfExpression.init(doc, snapshot);
|
||||||
|
|||||||
@@ -491,12 +491,12 @@ void FollowSymbolUnderCursor::findLink(
|
|||||||
{
|
{
|
||||||
Link link;
|
Link link;
|
||||||
|
|
||||||
int lineNumber = 0, positionInBlock = 0;
|
int line = 0;
|
||||||
|
int column = 0;
|
||||||
QTextCursor cursor = data.cursor();
|
QTextCursor cursor = data.cursor();
|
||||||
QTextDocument *document = cursor.document();
|
QTextDocument *document = cursor.document();
|
||||||
Utils::Text::convertPosition(document, cursor.position(), &lineNumber, &positionInBlock);
|
Utils::Text::convertPosition(document, cursor.position(), &line, &column);
|
||||||
const unsigned line = lineNumber;
|
const int positionInBlock = column - 1;
|
||||||
const unsigned column = positionInBlock + 1;
|
|
||||||
|
|
||||||
Snapshot snapshot = theSnapshot;
|
Snapshot snapshot = theSnapshot;
|
||||||
|
|
||||||
@@ -541,8 +541,8 @@ void FollowSymbolUnderCursor::findLink(
|
|||||||
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) positionInBlock) >= tk.utf16charsBegin()
|
if (static_cast<unsigned>(positionInBlock) >= tk.utf16charsBegin()
|
||||||
&& ((unsigned) positionInBlock) < tk.utf16charsEnd()) {
|
&& static_cast<unsigned>(positionInBlock) < tk.utf16charsEnd()) {
|
||||||
int closingParenthesisPos = tokens.size();
|
int closingParenthesisPos = tokens.size();
|
||||||
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))) {
|
||||||
@@ -584,8 +584,8 @@ void FollowSymbolUnderCursor::findLink(
|
|||||||
|
|
||||||
// In this case we want to look at one token before the current position to recognize
|
// In this case we want to look at one token before the current position to recognize
|
||||||
// an operator if the cursor is inside the actual operator: operator[$]
|
// an operator if the cursor is inside the actual operator: operator[$]
|
||||||
if (unsigned(positionInBlock) >= tk.utf16charsBegin()
|
if (static_cast<unsigned>(positionInBlock) >= tk.utf16charsBegin()
|
||||||
&& unsigned(positionInBlock) <= tk.utf16charsEnd()) {
|
&& static_cast<unsigned>(positionInBlock) <= tk.utf16charsEnd()) {
|
||||||
cursorRegionReached = true;
|
cursorRegionReached = true;
|
||||||
if (tk.is(T_OPERATOR)) {
|
if (tk.is(T_OPERATOR)) {
|
||||||
link = attemptFuncDeclDef(cursor, theSnapshot,
|
link = attemptFuncDeclDef(cursor, theSnapshot,
|
||||||
@@ -675,7 +675,7 @@ void FollowSymbolUnderCursor::findLink(
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Find the last symbol up to the cursor position
|
// Find the last symbol up to the cursor position
|
||||||
Scope *scope = doc->scopeAt(line, column);
|
Scope *scope = doc->scopeAt(line, positionInBlock);
|
||||||
if (!scope)
|
if (!scope)
|
||||||
return processLinkCallback(link);
|
return processLinkCallback(link);
|
||||||
|
|
||||||
@@ -698,19 +698,21 @@ void FollowSymbolUnderCursor::findLink(
|
|||||||
if (d->isDeclaration() || d->isFunction()) {
|
if (d->isDeclaration() || d->isFunction()) {
|
||||||
const QString fileName = QString::fromUtf8(d->fileName(), d->fileNameLength());
|
const QString fileName = QString::fromUtf8(d->fileName(), d->fileNameLength());
|
||||||
if (data.filePath().toString() == fileName) {
|
if (data.filePath().toString() == fileName) {
|
||||||
if (unsigned(lineNumber) == d->line()
|
if (static_cast<unsigned>(line) == d->line()
|
||||||
&& unsigned(positionInBlock) >= d->column()) { // TODO: check the end
|
&& static_cast<unsigned>(positionInBlock) >= d->column()) {
|
||||||
|
// TODO: check the end
|
||||||
result = r; // take the symbol under cursor.
|
result = r; // take the symbol under cursor.
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else if (d->isUsingDeclaration()) {
|
} else if (d->isUsingDeclaration()) {
|
||||||
int tokenBeginLineNumber = 0, tokenBeginColumnNumber = 0;
|
int tokenBeginLineNumber = 0;
|
||||||
|
int tokenBeginColumnNumber = 0;
|
||||||
Utils::Text::convertPosition(document, beginOfToken, &tokenBeginLineNumber,
|
Utils::Text::convertPosition(document, beginOfToken, &tokenBeginLineNumber,
|
||||||
&tokenBeginColumnNumber);
|
&tokenBeginColumnNumber);
|
||||||
if (unsigned(tokenBeginLineNumber) > d->line()
|
if (static_cast<unsigned>(tokenBeginLineNumber) > d->line()
|
||||||
|| (unsigned(tokenBeginLineNumber) == d->line()
|
|| (static_cast<unsigned>(tokenBeginLineNumber) == d->line()
|
||||||
&& unsigned(tokenBeginColumnNumber) > d->column())) {
|
&& static_cast<unsigned>(tokenBeginColumnNumber) >= d->column())) {
|
||||||
result = r; // take the symbol under cursor.
|
result = r; // take the symbol under cursor.
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -74,7 +74,7 @@ CPlusPlus::Symbol *AnalyzerUtils::findSymbolUnderCursor()
|
|||||||
CPlusPlus::ExpressionUnderCursor expressionUnderCursor(doc->languageFeatures());
|
CPlusPlus::ExpressionUnderCursor expressionUnderCursor(doc->languageFeatures());
|
||||||
moveCursorToEndOfName(&tc);
|
moveCursorToEndOfName(&tc);
|
||||||
const QString &expression = expressionUnderCursor(tc);
|
const QString &expression = expressionUnderCursor(tc);
|
||||||
CPlusPlus::Scope *scope = doc->scopeAt(line, column);
|
CPlusPlus::Scope *scope = doc->scopeAt(line, column - 1);
|
||||||
|
|
||||||
CPlusPlus::TypeOfExpression typeOfExpression;
|
CPlusPlus::TypeOfExpression typeOfExpression;
|
||||||
typeOfExpression.init(doc, snapshot);
|
typeOfExpression.init(doc, snapshot);
|
||||||
|
|||||||
@@ -329,7 +329,8 @@ static Document::Ptr addDefinition(const Snapshot &docTable,
|
|||||||
const QString contents = editor->textDocument()->plainText();
|
const QString contents = editor->textDocument()->plainText();
|
||||||
int column;
|
int column;
|
||||||
editor->convertPosition(contents.length(), line, &column);
|
editor->convertPosition(contents.length(), line, &column);
|
||||||
editor->gotoLine(*line, column);
|
// gotoLine accepts 0-based column.
|
||||||
|
editor->gotoLine(*line, column - 1);
|
||||||
editor->insert(definition);
|
editor->insert(definition);
|
||||||
*line += 1;
|
*line += 1;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -81,8 +81,10 @@ void ProFileEditorWidget::findLinkAt(const QTextCursor &cursor,
|
|||||||
{
|
{
|
||||||
Link link;
|
Link link;
|
||||||
|
|
||||||
int lineNumber = 0, positionInBlock = 0;
|
int line = 0;
|
||||||
convertPosition(cursor.position(), &lineNumber, &positionInBlock);
|
int column = 0;
|
||||||
|
convertPosition(cursor.position(), &line, &column);
|
||||||
|
const int positionInBlock = column - 1;
|
||||||
|
|
||||||
const QString block = cursor.block().text();
|
const QString block = cursor.block().text();
|
||||||
|
|
||||||
|
|||||||
@@ -128,7 +128,8 @@ void QmakeManager::addLibraryImpl(const QString &fileName, BaseTextEditor *edito
|
|||||||
// add extra \n in case the last line is not empty
|
// add extra \n in case the last line is not empty
|
||||||
int line, column;
|
int line, column;
|
||||||
editor->convertPosition(endOfDoc, &line, &column);
|
editor->convertPosition(endOfDoc, &line, &column);
|
||||||
if (!editor->textAt(endOfDoc - column, column).simplified().isEmpty())
|
const int positionInBlock = column - 1;
|
||||||
|
if (!editor->textAt(endOfDoc - positionInBlock, positionInBlock).simplified().isEmpty())
|
||||||
snippet = QLatin1Char('\n') + snippet;
|
snippet = QLatin1Char('\n') + snippet;
|
||||||
|
|
||||||
editor->insert(snippet);
|
editor->insert(snippet);
|
||||||
|
|||||||
@@ -133,9 +133,10 @@ void TextEditorWidget::jumpTextCursorToSelectedModelNode()
|
|||||||
|
|
||||||
const int nodeOffset = rewriterView->nodeOffset(selectedNode);
|
const int nodeOffset = rewriterView->nodeOffset(selectedNode);
|
||||||
if (nodeOffset > 0) {
|
if (nodeOffset > 0) {
|
||||||
int line, column;
|
int line, column;
|
||||||
m_textEditor->editorWidget()->convertPosition(nodeOffset, &line, &column);
|
m_textEditor->editorWidget()->convertPosition(nodeOffset, &line, &column);
|
||||||
m_textEditor->editorWidget()->gotoLine(line, column);
|
// line has to be 1 based, column 0 based!
|
||||||
|
m_textEditor->editorWidget()->gotoLine(line, column - 1);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
m_updateSelectionTimer.stop();
|
m_updateSelectionTimer.stop();
|
||||||
|
|||||||
@@ -374,7 +374,8 @@ void QmlDesignerPlugin::jumpTextCursorToSelectedModelNode()
|
|||||||
if (currentSelectedNode != selectedNode) {
|
if (currentSelectedNode != selectedNode) {
|
||||||
int line, column;
|
int line, column;
|
||||||
currentDesignDocument()->textEditor()->convertPosition(nodeOffset, &line, &column);
|
currentDesignDocument()->textEditor()->convertPosition(nodeOffset, &line, &column);
|
||||||
currentDesignDocument()->textEditor()->gotoLine(line, column);
|
// line has to be 1 based, column 0 based!
|
||||||
|
currentDesignDocument()->textEditor()->gotoLine(line, column - 1);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -3104,14 +3104,14 @@ bool TextEditorWidget::restoreState(const QByteArray &state)
|
|||||||
int version;
|
int version;
|
||||||
int vval;
|
int vval;
|
||||||
int hval;
|
int hval;
|
||||||
int lval;
|
int lineVal;
|
||||||
int cval;
|
int columnVal;
|
||||||
QDataStream stream(state);
|
QDataStream stream(state);
|
||||||
stream >> version;
|
stream >> version;
|
||||||
stream >> vval;
|
stream >> vval;
|
||||||
stream >> hval;
|
stream >> hval;
|
||||||
stream >> lval;
|
stream >> lineVal;
|
||||||
stream >> cval;
|
stream >> columnVal;
|
||||||
|
|
||||||
if (version >= 1) {
|
if (version >= 1) {
|
||||||
QList<int> collapsedBlocks;
|
QList<int> collapsedBlocks;
|
||||||
@@ -3137,7 +3137,8 @@ bool TextEditorWidget::restoreState(const QByteArray &state)
|
|||||||
}
|
}
|
||||||
|
|
||||||
d->m_lastCursorChangeWasInteresting = false; // avoid adding last position to history
|
d->m_lastCursorChangeWasInteresting = false; // avoid adding last position to history
|
||||||
gotoLine(lval, cval);
|
// line is 1-based, column is 0-based
|
||||||
|
gotoLine(lineVal, columnVal - 1);
|
||||||
verticalScrollBar()->setValue(vval);
|
verticalScrollBar()->setValue(vval);
|
||||||
horizontalScrollBar()->setValue(hval);
|
horizontalScrollBar()->setValue(hval);
|
||||||
d->saveCurrentCursorPositionForNavigation();
|
d->saveCurrentCursorPositionForNavigation();
|
||||||
|
|||||||
Reference in New Issue
Block a user