forked from qt-creator/qt-creator
Clang: Significantly improve ClangFormat plugin usability
What's new: 1. New LibFormat option is used to prevent lines shrink, which allows to drop most of tricks used before for that purpose. 2. Cached UTF-8 source code is used to improve performance 3. Improved error handling. 4. Slightly improved UI. Change-Id: I4605200fa103167369a40650b2e1ad2c61e8133b Reviewed-by: Marco Bubke <marco.bubke@qt.io>
This commit is contained in:
@@ -140,5 +140,20 @@ QTextCursor wordStartCursor(const QTextCursor &textCursor)
|
||||
return cursor;
|
||||
}
|
||||
|
||||
int utf8NthLineOffset(const QTextDocument *textDocument, const QByteArray &buffer, int line)
|
||||
{
|
||||
if (textDocument->characterCount() == buffer.size() + 1)
|
||||
return textDocument->findBlockByNumber(line - 1).position();
|
||||
|
||||
int pos = 0;
|
||||
for (int count = 0; count < line - 1; ++count) {
|
||||
pos = buffer.indexOf('\n', pos);
|
||||
if (pos == -1)
|
||||
return -1;
|
||||
++pos;
|
||||
}
|
||||
return pos;
|
||||
}
|
||||
|
||||
} // Text
|
||||
} // Utils
|
||||
|
||||
Reference in New Issue
Block a user