forked from qt-creator/qt-creator
ClangCodeModel: Another cursor adjustment
Change-Id: Ie4859a52b12b3e87a65bd8c04e0123e6f34a9e73 Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org> Reviewed-by: David Schulz <david.schulz@qt.io> Reviewed-by: <github-actions-qt-creator@cristianadam.eu>
This commit is contained in:
@@ -2058,17 +2058,32 @@ QTextCursor ClangdClient::Private::adjustedCursor(const QTextCursor &cursor,
|
||||
if (!cppDoc)
|
||||
return cursor;
|
||||
const QList<AST *> builtinAstPath = ASTPath(cppDoc)(cursor);
|
||||
if (builtinAstPath.isEmpty())
|
||||
return cursor;
|
||||
const TranslationUnit * const tu = cppDoc->translationUnit();
|
||||
const auto posForToken = [doc, tu](int tok) {
|
||||
int line, column;
|
||||
tu->getTokenPosition(tok, &line, &column);
|
||||
return Utils::Text::positionInText(doc->document(), line, column);
|
||||
};
|
||||
const auto endPosForToken = [doc, tu](int tok) {
|
||||
int line, column;
|
||||
tu->getTokenEndPosition(tok, &line, &column);
|
||||
return Utils::Text::positionInText(doc->document(), line, column);
|
||||
};
|
||||
const auto leftMovedCursor = [cursor] {
|
||||
QTextCursor c = cursor;
|
||||
c.setPosition(cursor.position() - 1);
|
||||
return c;
|
||||
};
|
||||
|
||||
// enum E { v1|, v2 };
|
||||
if (const EnumeratorAST * const enumAst = builtinAstPath.last()->asEnumerator()) {
|
||||
if (endPosForToken(enumAst->identifier_token) == cursor.position())
|
||||
return leftMovedCursor();
|
||||
return cursor;
|
||||
}
|
||||
|
||||
for (auto it = builtinAstPath.rbegin(); it != builtinAstPath.rend(); ++it) {
|
||||
|
||||
// s|.x or s|->x
|
||||
|
||||
Reference in New Issue
Block a user