forked from qt-creator/qt-creator
Clang: fix incomplete include text underlining
Fix invalid include text selection. Task-number: QTCREATORBUG-15471 Change-Id: Ifbe00a7215f2307648e815cb283691496d02c4d0 Reviewed-by: Nikolai Kosjar <nikolai.kosjar@qt.io>
This commit is contained in:
@@ -81,12 +81,44 @@ void addRangeSelections(const ClangBackEnd::DiagnosticContainer &diagnostic,
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
QChar selectionEndChar(const QChar startSymbol)
|
||||||
|
{
|
||||||
|
if (startSymbol == '"')
|
||||||
|
return QLatin1Char('"');
|
||||||
|
if (startSymbol == '<')
|
||||||
|
return QLatin1Char('>');
|
||||||
|
return QChar();
|
||||||
|
}
|
||||||
|
|
||||||
|
void selectToLocationEnd(QTextCursor &cursor)
|
||||||
|
{
|
||||||
|
const QTextBlock textBlock = cursor.document()->findBlock(cursor.position());
|
||||||
|
const QString simplifiedStr = textBlock.text().simplified();
|
||||||
|
if (!simplifiedStr.startsWith("#include") && !simplifiedStr.startsWith("# include")) {
|
||||||
|
// General case, not the line with #include
|
||||||
|
cursor.movePosition(QTextCursor::EndOfWord, QTextCursor::KeepAnchor);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
const QChar endChar = selectionEndChar(cursor.document()->characterAt(cursor.position()));
|
||||||
|
if (endChar.isNull()) {
|
||||||
|
cursor.movePosition(QTextCursor::EndOfWord, QTextCursor::KeepAnchor);
|
||||||
|
} else {
|
||||||
|
const int endPosition = textBlock.text().indexOf(endChar, cursor.position()
|
||||||
|
- textBlock.position() + 1);
|
||||||
|
if (endPosition >= 0)
|
||||||
|
cursor.setPosition(textBlock.position() + endPosition + 1, QTextCursor::KeepAnchor);
|
||||||
|
else
|
||||||
|
cursor.movePosition(QTextCursor::EndOfLine, QTextCursor::KeepAnchor);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
QTextCursor createSelectionCursor(QTextDocument *textDocument,
|
QTextCursor createSelectionCursor(QTextDocument *textDocument,
|
||||||
const ClangBackEnd::SourceLocationContainer &sourceLocationContainer)
|
const ClangBackEnd::SourceLocationContainer &sourceLocationContainer)
|
||||||
{
|
{
|
||||||
QTextCursor cursor(textDocument);
|
QTextCursor cursor(textDocument);
|
||||||
cursor.setPosition(positionInText(textDocument, sourceLocationContainer));
|
cursor.setPosition(positionInText(textDocument, sourceLocationContainer));
|
||||||
cursor.movePosition(QTextCursor::EndOfWord, QTextCursor::KeepAnchor);
|
selectToLocationEnd(cursor);
|
||||||
|
|
||||||
if (!cursor.hasSelection()) {
|
if (!cursor.hasSelection()) {
|
||||||
cursor.setPosition(positionInText(textDocument, sourceLocationContainer) - 1);
|
cursor.setPosition(positionInText(textDocument, sourceLocationContainer) - 1);
|
||||||
|
|||||||
Reference in New Issue
Block a user