forked from qt-creator/qt-creator
Utils: make column of convertPosition 0-based to merge it into Position
Change-Id: I239b3cb33b8ad59ac4097c919155ab5ca7d57b8e Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org> Reviewed-by: Jarek Kobus <jaroslaw.kobus@qt.io>
This commit is contained in:
@@ -275,7 +275,7 @@ Position Position::withOffset(int offset, const QTextDocument *doc) const
|
||||
int line;
|
||||
int character;
|
||||
Utils::Text::convertPosition(doc, toPositionInDocument(doc) + offset, &line, &character);
|
||||
return Position(line - 1, character - 1);
|
||||
return Position(line - 1, character);
|
||||
}
|
||||
|
||||
Range::Range(const Position &start, const Position &end)
|
||||
@@ -288,11 +288,11 @@ Range::Range(const QTextCursor &cursor)
|
||||
{
|
||||
int line, character = 0;
|
||||
Utils::Text::convertPosition(cursor.document(), cursor.selectionStart(), &line, &character);
|
||||
if (line <= 0 || character <= 0)
|
||||
if (line <= 0 || character < 0)
|
||||
return;
|
||||
setStart(Position(line - 1, character - 1));
|
||||
Utils::Text::convertPosition(cursor.document(), cursor.selectionEnd(), &line, &character);
|
||||
if (line <= 0 || character <= 0)
|
||||
if (line <= 0 || character < 0)
|
||||
return;
|
||||
setEnd(Position(line - 1, character - 1));
|
||||
}
|
||||
|
||||
@@ -102,12 +102,12 @@ bool convertPosition(const QTextDocument *document, int pos, int *line, int *col
|
||||
QTextBlock block = document->findBlock(pos);
|
||||
if (!block.isValid()) {
|
||||
(*line) = -1;
|
||||
(*column) = -1;
|
||||
(*column) = 0;
|
||||
return false;
|
||||
} else {
|
||||
// line and column are both 1-based
|
||||
(*line) = block.blockNumber() + 1;
|
||||
(*column) = pos - block.position() + 1;
|
||||
(*column) = pos - block.position();
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -68,7 +68,7 @@ using Replacements = std::vector<Replacement>;
|
||||
|
||||
QTCREATOR_UTILS_EXPORT void applyReplacements(QTextDocument *doc, const Replacements &replacements);
|
||||
|
||||
// line is 1-based, column is 1-based
|
||||
// line is 1-based, column is 0-based
|
||||
QTCREATOR_UTILS_EXPORT bool convertPosition(const QTextDocument *document,
|
||||
int pos,
|
||||
int *line, int *column);
|
||||
|
||||
@@ -394,10 +394,10 @@ void QPropertyHighlighter::Private::addResult(TextStyle textStyle, int symbolOff
|
||||
const Symbol &s = parser.symbol_lookup(symbolOffset);
|
||||
int line, column;
|
||||
Utils::Text::convertPosition(document, position + s.from, &line, &column);
|
||||
if (line > 0 && column > 0) {
|
||||
if (line > 0 && column >= 0) {
|
||||
TextStyles styles;
|
||||
styles.mainStyle = textStyle;
|
||||
results << HighlightingResult(line, column, s.len, styles);
|
||||
results << HighlightingResult(line, column + 1, s.len, styles);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -571,10 +571,12 @@ void ExtraHighlightingResultsCollector::insertAngleBracketInfo(int searchStart1,
|
||||
result.useTextSyles = true;
|
||||
result.textStyles.mainStyle = C_PUNCTUATION;
|
||||
Utils::Text::convertPosition(m_doc, absOpeningAngleBracketPos, &result.line, &result.column);
|
||||
++result.column;
|
||||
result.length = 1;
|
||||
result.kind = CppEditor::SemanticHighlighter::AngleBracketOpen;
|
||||
insertResult(result);
|
||||
Utils::Text::convertPosition(m_doc, absClosingAngleBracketPos, &result.line, &result.column);
|
||||
++result.column;
|
||||
result.kind = CppEditor::SemanticHighlighter::AngleBracketClose;
|
||||
insertResult(result);
|
||||
}
|
||||
@@ -646,10 +648,12 @@ void ExtraHighlightingResultsCollector::collectFromNode(const ClangdAstNode &nod
|
||||
result.textStyles.mainStyle = C_PUNCTUATION;
|
||||
result.textStyles.mixinStyles.push_back(C_OPERATOR);
|
||||
Utils::Text::convertPosition(m_doc, absQuestionMarkPos, &result.line, &result.column);
|
||||
++result.column;
|
||||
result.length = 1;
|
||||
result.kind = CppEditor::SemanticHighlighter::TernaryIf;
|
||||
insertResult(result);
|
||||
Utils::Text::convertPosition(m_doc, absColonPos, &result.line, &result.column);
|
||||
++result.column;
|
||||
result.kind = CppEditor::SemanticHighlighter::TernaryElse;
|
||||
insertResult(result);
|
||||
return;
|
||||
@@ -837,10 +841,12 @@ void ExtraHighlightingResultsCollector::collectFromNode(const ClangdAstNode &nod
|
||||
Utils::Text::convertPosition(m_doc,
|
||||
nodeStartPos + openingBracketOffset,
|
||||
&result.line, &result.column);
|
||||
++result.column;
|
||||
insertResult(result);
|
||||
Utils::Text::convertPosition(m_doc,
|
||||
nodeStartPos + closingBracketOffset,
|
||||
&result.line, &result.column);
|
||||
++result.column;
|
||||
insertResult(result);
|
||||
}
|
||||
return;
|
||||
@@ -885,6 +891,7 @@ void ExtraHighlightingResultsCollector::collectFromNode(const ClangdAstNode &nod
|
||||
const int opStringOffsetInDoc = nodeStartPos + opStringOffset
|
||||
+ detail.length() - opStringLen;
|
||||
Utils::Text::convertPosition(m_doc, opStringOffsetInDoc, &result.line, &result.column);
|
||||
++result.column;
|
||||
result.length = opStringLen;
|
||||
if (isArray || isCall)
|
||||
result.length = 1;
|
||||
@@ -906,9 +913,11 @@ void ExtraHighlightingResultsCollector::collectFromNode(const ClangdAstNode &nod
|
||||
return;
|
||||
Utils::Text::convertPosition(m_doc, nodeStartPos + openingParenOffset,
|
||||
&result.line, &result.column);
|
||||
++result.column;
|
||||
insertResult(result);
|
||||
Utils::Text::convertPosition(m_doc, nodeStartPos + closingParenOffset,
|
||||
&result.line, &result.column);
|
||||
++result.column;
|
||||
insertResult(result);
|
||||
}
|
||||
|
||||
|
||||
@@ -1539,7 +1539,7 @@ void ClangdTestCompletion::testCompleteGlobals()
|
||||
Manipulator manipulator;
|
||||
item->apply(manipulator, cursorPos);
|
||||
QCOMPARE(manipulator.getLine(7), " globalFunction() /* COMPLETE HERE */");
|
||||
QCOMPARE(manipulator.cursorPos(), qMakePair(7, 20));
|
||||
QCOMPARE(manipulator.cursorPos(), qMakePair(7, 19));
|
||||
QCOMPARE(manipulator.skipPos(), -1);
|
||||
}
|
||||
|
||||
@@ -1559,7 +1559,7 @@ void ClangdTestCompletion::testCompleteMembers()
|
||||
Manipulator manipulator;
|
||||
item->apply(manipulator, cursorPos);
|
||||
QCOMPARE(manipulator.getLine(7), " s.member /* COMPLETE HERE */");
|
||||
QCOMPARE(manipulator.cursorPos(), qMakePair(7, 13));
|
||||
QCOMPARE(manipulator.cursorPos(), qMakePair(7, 12));
|
||||
QCOMPARE(manipulator.skipPos(), -1);
|
||||
}
|
||||
|
||||
@@ -1577,7 +1577,7 @@ void ClangdTestCompletion::testCompleteMembersFromInside()
|
||||
Manipulator manipulator;
|
||||
item->apply(manipulator, cursorPos);
|
||||
QCOMPARE(manipulator.getLine(4), " privateFunc() /* COMPLETE HERE */");
|
||||
QCOMPARE(manipulator.cursorPos(), qMakePair(4, 22));
|
||||
QCOMPARE(manipulator.cursorPos(), qMakePair(4, 21));
|
||||
QCOMPARE(manipulator.skipPos(), -1);
|
||||
}
|
||||
|
||||
@@ -1595,7 +1595,7 @@ void ClangdTestCompletion::testCompleteMembersFromOutside()
|
||||
Manipulator manipulator;
|
||||
item->apply(manipulator, cursorPos);
|
||||
QCOMPARE(manipulator.getLine(13), " c.publicFunc() /* COMPLETE HERE */");
|
||||
QCOMPARE(manipulator.cursorPos(), qMakePair(13, 19));
|
||||
QCOMPARE(manipulator.cursorPos(), qMakePair(13, 18));
|
||||
QCOMPARE(manipulator.skipPos(), -1);
|
||||
}
|
||||
|
||||
@@ -1613,7 +1613,7 @@ void ClangdTestCompletion::testCompleteMembersFromFriend()
|
||||
Manipulator manipulator;
|
||||
item->apply(manipulator, cursorPos);
|
||||
QCOMPARE(manipulator.getLine(14), " C().privateFunc() /* COMPLETE HERE */");
|
||||
QCOMPARE(manipulator.cursorPos(), qMakePair(14, 22));
|
||||
QCOMPARE(manipulator.cursorPos(), qMakePair(14, 21));
|
||||
QCOMPARE(manipulator.skipPos(), -1);
|
||||
}
|
||||
|
||||
@@ -1630,7 +1630,7 @@ void ClangdTestCompletion::testFunctionAddress()
|
||||
Manipulator manipulator;
|
||||
item->apply(manipulator, cursorPos);
|
||||
QCOMPARE(manipulator.getLine(7), " const auto p = &S::memberFunc /* COMPLETE HERE */;");
|
||||
QCOMPARE(manipulator.cursorPos(), qMakePair(7, 34));
|
||||
QCOMPARE(manipulator.cursorPos(), qMakePair(7, 33));
|
||||
QCOMPARE(manipulator.skipPos(), -1);
|
||||
}
|
||||
|
||||
@@ -1696,7 +1696,7 @@ void ClangdTestCompletion::testCompleteClassAndConstructor()
|
||||
Manipulator manipulator;
|
||||
item->apply(manipulator, cursorPos);
|
||||
QCOMPARE(manipulator.getLine(7), " Foo( /* COMPLETE HERE */");
|
||||
QCOMPARE(manipulator.cursorPos(), qMakePair(7, 9));
|
||||
QCOMPARE(manipulator.cursorPos(), qMakePair(7, 8));
|
||||
QCOMPARE(manipulator.skipPos(), -1);
|
||||
}
|
||||
|
||||
@@ -1723,7 +1723,7 @@ void ClangdTestCompletion::testCompleteWithDotToArrowCorrection()
|
||||
Manipulator manipulator;
|
||||
item->apply(manipulator, cursorPos);
|
||||
QCOMPARE(manipulator.getLine(4), " bar->member /* COMPLETE HERE */");
|
||||
QCOMPARE(manipulator.cursorPos(), qMakePair(4, 16));
|
||||
QCOMPARE(manipulator.cursorPos(), qMakePair(4, 15));
|
||||
QCOMPARE(manipulator.skipPos(), -1);
|
||||
}
|
||||
|
||||
@@ -1754,7 +1754,7 @@ void ClangdTestCompletion::testCompleteCodeInGeneratedUiFile()
|
||||
Manipulator manipulator;
|
||||
item->apply(manipulator, cursorPos);
|
||||
QCOMPARE(manipulator.getLine(34), " ui->setupUi( /* COMPLETE HERE */");
|
||||
QCOMPARE(manipulator.cursorPos(), qMakePair(34, 17));
|
||||
QCOMPARE(manipulator.cursorPos(), qMakePair(34, 16));
|
||||
QCOMPARE(manipulator.skipPos(), -1);
|
||||
}
|
||||
|
||||
@@ -1882,7 +1882,7 @@ void ClangdTestCompletion::getProposal(const QString &fileName,
|
||||
int line, column;
|
||||
Text::convertPosition(doc->document(), pos, &line, &column);
|
||||
const auto editor = qobject_cast<BaseTextEditor *>(
|
||||
EditorManager::openEditorAt({doc->filePath(), line, column - 1}));
|
||||
EditorManager::openEditorAt({doc->filePath(), line, column}));
|
||||
QVERIFY(editor);
|
||||
QCOMPARE(EditorManager::currentEditor(), editor);
|
||||
QCOMPARE(editor->textDocument(), doc);
|
||||
|
||||
@@ -147,18 +147,17 @@ void CMakeEditorWidget::findLinkAt(const QTextCursor &cursor,
|
||||
int line = 0;
|
||||
int column = 0;
|
||||
convertPosition(cursor.position(), &line, &column);
|
||||
const int positionInBlock = column - 1;
|
||||
|
||||
const QString block = cursor.block().text();
|
||||
|
||||
// check if the current position is commented out
|
||||
const int hashPos = block.indexOf(QLatin1Char('#'));
|
||||
if (hashPos >= 0 && hashPos < positionInBlock)
|
||||
if (hashPos >= 0 && hashPos < column)
|
||||
return processLinkCallback(link);
|
||||
|
||||
// find the beginning of a filename
|
||||
QString buffer;
|
||||
int beginPos = positionInBlock - 1;
|
||||
int beginPos = column - 1;
|
||||
while (beginPos >= 0) {
|
||||
if (isValidFileNameChar(block, beginPos)) {
|
||||
buffer.prepend(block.at(beginPos));
|
||||
@@ -169,7 +168,7 @@ void CMakeEditorWidget::findLinkAt(const QTextCursor &cursor,
|
||||
}
|
||||
|
||||
// find the end of a filename
|
||||
int endPos = positionInBlock;
|
||||
int endPos = column;
|
||||
while (endPos < block.count()) {
|
||||
if (isValidFileNameChar(block, endPos)) {
|
||||
buffer.append(block.at(endPos));
|
||||
@@ -199,8 +198,8 @@ void CMakeEditorWidget::findLinkAt(const QTextCursor &cursor,
|
||||
return processLinkCallback(link);
|
||||
}
|
||||
link.targetFilePath = Utils::FilePath::fromString(fileName);
|
||||
link.linkTextStart = cursor.position() - positionInBlock + beginPos + 1;
|
||||
link.linkTextEnd = cursor.position() - positionInBlock + endPos;
|
||||
link.linkTextStart = cursor.position() - column + beginPos + 1;
|
||||
link.linkTextEnd = cursor.position() - column + endPos;
|
||||
}
|
||||
processLinkCallback(link);
|
||||
}
|
||||
|
||||
@@ -322,7 +322,7 @@ QFuture<CursorInfo> BuiltinCursorInfo::run(const CursorInfoParams &cursorInfoPar
|
||||
QString expression;
|
||||
Scope *scope = canonicalSymbol.getScopeAndExpression(textCursor, &expression);
|
||||
|
||||
return Utils::asyncRun(&FindUses::find, document, snapshot, line, column, scope, expression);
|
||||
return Utils::asyncRun(&FindUses::find, document, snapshot, line, column + 1, scope, expression);
|
||||
}
|
||||
|
||||
SemanticInfo::LocalUseMap
|
||||
|
||||
@@ -92,10 +92,10 @@ CheckSymbols *createHighlighter(const CPlusPlus::Document::Ptr &doc,
|
||||
for (const CPlusPlus::Macro ¯o : doc->definedMacros()) {
|
||||
int line, column;
|
||||
convertPosition(textDocument, macro.utf16CharOffset(), &line, &column);
|
||||
QTC_ASSERT(line >= 0 && column >= 0, qDebug() << doc->filePath() << macro.toString();
|
||||
QTC_ASSERT(line > 0 && column >= 0, qDebug() << doc->filePath() << macro.toString();
|
||||
continue);
|
||||
|
||||
Result use(line, column, macro.nameToQString().size(), SemanticHighlighter::MacroUse);
|
||||
Result use(line, column + 1, macro.nameToQString().size(), SemanticHighlighter::MacroUse);
|
||||
macroUses.append(use);
|
||||
}
|
||||
|
||||
@@ -119,10 +119,10 @@ CheckSymbols *createHighlighter(const CPlusPlus::Document::Ptr &doc,
|
||||
|
||||
int line, column;
|
||||
convertPosition(textDocument, macro.utf16charsBegin(), &line, &column);
|
||||
QTC_ASSERT(line >= 0 && column >= 0, qDebug() << doc->filePath()
|
||||
QTC_ASSERT(line > 0 && column >= 0, qDebug() << doc->filePath()
|
||||
<< macro.macro().toString(); continue);
|
||||
|
||||
Result use(line, column, name.size(), SemanticHighlighter::MacroUse);
|
||||
Result use(line, column + 1, name.size(), SemanticHighlighter::MacroUse);
|
||||
macroUses.append(use);
|
||||
}
|
||||
|
||||
|
||||
@@ -51,7 +51,7 @@ Scope *CanonicalSymbol::getScopeAndExpression(const QTextCursor &cursor, QString
|
||||
|
||||
ExpressionUnderCursor expressionUnderCursor(m_document->languageFeatures());
|
||||
*code = expressionUnderCursor(tc);
|
||||
return m_document->scopeAt(line, column - 1);
|
||||
return m_document->scopeAt(line, column);
|
||||
}
|
||||
|
||||
Symbol *CanonicalSymbol::operator()(const QTextCursor &cursor)
|
||||
|
||||
@@ -1041,7 +1041,7 @@ int InternalCppCompletionAssistProcessor::startCompletionHelper()
|
||||
int line = 0, column = 0;
|
||||
Utils::Text::convertPosition(interface()->textDocument(), startOfExpression, &line, &column);
|
||||
return startCompletionInternal(interface()->filePath(),
|
||||
line, column - 1, expression, endOfExpression);
|
||||
line, column, expression, endOfExpression);
|
||||
}
|
||||
|
||||
bool InternalCppCompletionAssistProcessor::tryObjCCompletion()
|
||||
@@ -1074,7 +1074,7 @@ bool InternalCppCompletionAssistProcessor::tryObjCCompletion()
|
||||
int line = 0, column = 0;
|
||||
Utils::Text::convertPosition(interface()->textDocument(), interface()->position(), &line,
|
||||
&column);
|
||||
Scope *scope = thisDocument->scopeAt(line, column - 1);
|
||||
Scope *scope = thisDocument->scopeAt(line, column);
|
||||
if (!scope)
|
||||
return false;
|
||||
|
||||
@@ -1989,7 +1989,7 @@ bool InternalCppCompletionAssistProcessor::completeConstructorOrFunction(const Q
|
||||
int lineSigned = 0, columnSigned = 0;
|
||||
Utils::Text::convertPosition(interface()->textDocument(), interface()->position(),
|
||||
&lineSigned, &columnSigned);
|
||||
unsigned line = lineSigned, column = columnSigned - 1;
|
||||
unsigned line = lineSigned, column = columnSigned;
|
||||
|
||||
// find a scope that encloses the current location, starting from the lastVisibileSymbol
|
||||
// and moving outwards
|
||||
|
||||
@@ -151,7 +151,7 @@ void CppEditorOutline::updateIndexNow()
|
||||
|
||||
int line = 0, column = 0;
|
||||
m_editorWidget->convertPosition(m_editorWidget->position(), &line, &column);
|
||||
QModelIndex comboIndex = m_model->indexForPosition(line, column - 1);
|
||||
QModelIndex comboIndex = m_model->indexForPosition(line, column);
|
||||
|
||||
if (comboIndex.isValid()) {
|
||||
QSignalBlocker blocker(m_combo);
|
||||
|
||||
@@ -562,7 +562,7 @@ public:
|
||||
expression = expressionUnderCursor(m_tc);
|
||||
|
||||
// Fetch the expression's code
|
||||
*scope = doc->scopeAt(line, column - 1);
|
||||
*scope = doc->scopeAt(line, column);
|
||||
return true;
|
||||
}
|
||||
QFuture<QSharedPointer<CppElement>> syncExec(const CPlusPlus::Snapshot &,
|
||||
|
||||
@@ -485,7 +485,6 @@ void FollowSymbolUnderCursor::findLink(
|
||||
int line = 0;
|
||||
int column = 0;
|
||||
Utils::Text::convertPosition(document, cursor.position(), &line, &column);
|
||||
const int positionInBlock = column - 1;
|
||||
|
||||
Snapshot snapshot = theSnapshot;
|
||||
|
||||
@@ -530,7 +529,7 @@ void FollowSymbolUnderCursor::findLink(
|
||||
for (int i = 0; i < tokens.size(); ++i) {
|
||||
const Token &tk = tokens.at(i);
|
||||
|
||||
if (positionInBlock >= tk.utf16charsBegin() && positionInBlock < tk.utf16charsEnd()) {
|
||||
if (column >= tk.utf16charsBegin() && column < tk.utf16charsEnd()) {
|
||||
int closingParenthesisPos = tokens.size();
|
||||
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))) {
|
||||
@@ -572,7 +571,7 @@ void FollowSymbolUnderCursor::findLink(
|
||||
|
||||
// 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[$]
|
||||
if (positionInBlock >= tk.utf16charsBegin() && positionInBlock <= tk.utf16charsEnd()) {
|
||||
if (column >= tk.utf16charsBegin() && column <= tk.utf16charsEnd()) {
|
||||
cursorRegionReached = true;
|
||||
if (tk.is(T_OPERATOR)) {
|
||||
link = attemptDeclDef(cursor, theSnapshot,
|
||||
@@ -582,7 +581,7 @@ void FollowSymbolUnderCursor::findLink(
|
||||
} else if (tk.isPunctuationOrOperator() && i > 0 && tokens.at(i - 1).is(T_OPERATOR)) {
|
||||
QTextCursor c = cursor;
|
||||
c.movePosition(QTextCursor::Left, QTextCursor::MoveAnchor,
|
||||
positionInBlock - tokens.at(i - 1).utf16charsBegin());
|
||||
column - tokens.at(i - 1).utf16charsBegin());
|
||||
link = attemptDeclDef(c, theSnapshot, documentFromSemanticInfo, symbolFinder);
|
||||
if (link.hasValidLinkText())
|
||||
return processLinkCallback(link);
|
||||
@@ -662,7 +661,7 @@ void FollowSymbolUnderCursor::findLink(
|
||||
}
|
||||
|
||||
// Find the last symbol up to the cursor position
|
||||
Scope *scope = doc->scopeAt(line, positionInBlock);
|
||||
Scope *scope = doc->scopeAt(line, column);
|
||||
if (!scope)
|
||||
return processLinkCallback(link);
|
||||
|
||||
@@ -684,7 +683,7 @@ void FollowSymbolUnderCursor::findLink(
|
||||
if (Symbol *d = r.declaration()) {
|
||||
if (d->asDeclaration() || d->asFunction()) {
|
||||
if (data.filePath() == d->filePath()) {
|
||||
if (line == d->line() && positionInBlock >= d->column()) {
|
||||
if (line == d->line() && column >= d->column()) {
|
||||
// TODO: check the end
|
||||
result = r; // take the symbol under cursor.
|
||||
break;
|
||||
@@ -697,7 +696,7 @@ void FollowSymbolUnderCursor::findLink(
|
||||
&tokenBeginColumnNumber);
|
||||
if (tokenBeginLineNumber > d->line()
|
||||
|| (tokenBeginLineNumber == d->line()
|
||||
&& tokenBeginColumnNumber >= d->column())) {
|
||||
&& tokenBeginColumnNumber + 1 >= d->column())) {
|
||||
result = r; // take the symbol under cursor.
|
||||
break;
|
||||
}
|
||||
|
||||
@@ -168,7 +168,7 @@ void CppOutlineWidget::updateIndexNow()
|
||||
|
||||
int line = 0, column = 0;
|
||||
m_editor->convertPosition(m_editor->position(), &line, &column);
|
||||
QModelIndex index = m_model->indexForPosition(line, column - 1);
|
||||
QModelIndex index = m_model->indexForPosition(line, column);
|
||||
|
||||
if (index.isValid()) {
|
||||
m_blockCursorSync = true;
|
||||
|
||||
@@ -104,7 +104,7 @@ SelectionList UseSelectionsTestCase::toSelectionList(
|
||||
int line, column;
|
||||
const int position = qMin(selection.cursor.position(), selection.cursor.anchor());
|
||||
m_editorWidget->convertPosition(position, &line, &column);
|
||||
result << Selection(line, column - 1, selection.cursor.selectedText().length());
|
||||
result << Selection(line, column, selection.cursor.selectedText().length());
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
@@ -52,7 +52,7 @@ CPlusPlus::Symbol *AnalyzerUtils::findSymbolUnderCursor()
|
||||
CPlusPlus::ExpressionUnderCursor expressionUnderCursor(doc->languageFeatures());
|
||||
moveCursorToEndOfName(&tc);
|
||||
const QString &expression = expressionUnderCursor(tc);
|
||||
CPlusPlus::Scope *scope = doc->scopeAt(line, column - 1);
|
||||
CPlusPlus::Scope *scope = doc->scopeAt(line, column);
|
||||
|
||||
CPlusPlus::TypeOfExpression typeOfExpression;
|
||||
typeOfExpression.init(doc, snapshot);
|
||||
|
||||
@@ -1164,6 +1164,7 @@ void DebuggerToolTipManagerPrivate::slotTooltipOverrideRequested
|
||||
context.fileName = document->filePath();
|
||||
context.position = pos;
|
||||
editorWidget->convertPosition(pos, &context.line, &context.column);
|
||||
++context.column;
|
||||
QString raw = cppExpressionAt(editorWidget, context.position, &context.line, &context.column,
|
||||
&context.function, &context.scopeFromLine, &context.scopeToLine);
|
||||
context.expression = fixCppExpression(raw);
|
||||
|
||||
@@ -447,7 +447,6 @@ IAssistProposal *LanguageClientCompletionAssistProcessor::perform()
|
||||
if (!Utils::Text::convertPosition(interface()->textDocument(), m_pos, &line, &column))
|
||||
return nullptr;
|
||||
--line; // line is 0 based in the protocol
|
||||
--column; // column is 0 based in the protocol
|
||||
params.setPosition({line, column});
|
||||
params.setContext(context);
|
||||
params.setTextDocument(
|
||||
|
||||
@@ -142,8 +142,8 @@ private:
|
||||
{
|
||||
int line = 0, column = 0;
|
||||
Utils::Text::convertPosition(interface->textDocument(), pos, &line, &column);
|
||||
QTC_ASSERT(column >= 1, return nullptr);
|
||||
return suggest->sug(interface->filePath().toString(), line, column - 1, dirtyFile);
|
||||
QTC_ASSERT(column >= 0, return nullptr);
|
||||
return suggest->sug(interface->filePath().toString(), line, column, dirtyFile);
|
||||
}
|
||||
|
||||
static std::unique_ptr<QTemporaryFile> writeDirtyFile(const TextEditor::AssistInterface *interface)
|
||||
|
||||
@@ -50,7 +50,7 @@ void NimTextEditorWidget::findLinkAt(const QTextCursor &c, const Utils::LinkHand
|
||||
|
||||
std::shared_ptr<NimSuggestClientRequest> request = suggest->def(path.toString(),
|
||||
line,
|
||||
column - 1,
|
||||
column,
|
||||
dirtyFile->fileName());
|
||||
|
||||
if (!request)
|
||||
|
||||
@@ -117,23 +117,22 @@ void ProFileEditorWidget::findLinkAt(const QTextCursor &cursor,
|
||||
int line = 0;
|
||||
int column = 0;
|
||||
convertPosition(cursor.position(), &line, &column);
|
||||
const int positionInBlock = column - 1;
|
||||
|
||||
const QString block = cursor.block().text();
|
||||
|
||||
// check if the current position is commented out
|
||||
const int hashPos = block.indexOf(QLatin1Char('#'));
|
||||
if (hashPos >= 0 && hashPos < positionInBlock)
|
||||
if (hashPos >= 0 && hashPos < column)
|
||||
return processLinkCallback(link);
|
||||
|
||||
// find the beginning of a filename
|
||||
QString buffer;
|
||||
int beginPos = positionInBlock - 1;
|
||||
int endPos = positionInBlock;
|
||||
int beginPos = column - 1;
|
||||
int endPos = column;
|
||||
|
||||
// Check is cursor is somewhere on $${PWD}:
|
||||
const int chunkStart = std::max(0, positionInBlock - 7);
|
||||
const int chunkLength = 14 + std::min(0, positionInBlock - 7);
|
||||
const int chunkStart = std::max(0, column - 7);
|
||||
const int chunkLength = 14 + std::min(0, column - 7);
|
||||
QString chunk = block.mid(chunkStart, chunkLength);
|
||||
|
||||
const QString curlyPwd = "$${PWD}";
|
||||
@@ -145,7 +144,7 @@ void ProFileEditorWidget::findLinkAt(const QTextCursor &cursor,
|
||||
if (posCurlyPwd >= 0) {
|
||||
const int end = chunkStart + posCurlyPwd + curlyPwd.count();
|
||||
const int start = chunkStart + posCurlyPwd;
|
||||
if (start <= positionInBlock && end >= positionInBlock) {
|
||||
if (start <= column && end >= column) {
|
||||
buffer = pwd;
|
||||
beginPos = chunkStart + posCurlyPwd - 1;
|
||||
endPos = end;
|
||||
@@ -154,7 +153,7 @@ void ProFileEditorWidget::findLinkAt(const QTextCursor &cursor,
|
||||
} else if (posPwd >= 0) {
|
||||
const int end = chunkStart + posPwd + pwd.count();
|
||||
const int start = chunkStart + posPwd;
|
||||
if (start <= positionInBlock && end >= positionInBlock) {
|
||||
if (start <= column && end >= column) {
|
||||
buffer = pwd;
|
||||
beginPos = start - 1;
|
||||
endPos = end;
|
||||
@@ -229,8 +228,8 @@ void ProFileEditorWidget::findLinkAt(const QTextCursor &cursor,
|
||||
link.targetFilePath = FilePath::fromString(checkForPrfFile(buffer));
|
||||
}
|
||||
if (!link.targetFilePath.isEmpty()) {
|
||||
link.linkTextStart = cursor.position() - positionInBlock + beginPos + 1;
|
||||
link.linkTextEnd = cursor.position() - positionInBlock + endPos;
|
||||
link.linkTextStart = cursor.position() - column + beginPos + 1;
|
||||
link.linkTextEnd = cursor.position() - column + endPos;
|
||||
}
|
||||
processLinkCallback(link);
|
||||
}
|
||||
|
||||
@@ -3331,7 +3331,7 @@ void TextEditorWidget::restoreState(const QByteArray &state)
|
||||
|
||||
d->m_lastCursorChangeWasInteresting = false; // avoid adding last position to history
|
||||
// line is 1-based, column is 0-based
|
||||
gotoLine(lineVal, columnVal - 1);
|
||||
gotoLine(lineVal, columnVal);
|
||||
verticalScrollBar()->setValue(vval);
|
||||
horizontalScrollBar()->setValue(hval);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user