ClangFormat: Fix crashes when new project is created

Indenter is used by wizards so make sure it works.

Change-Id: If26eae322e26bf2e32cb86acf45e7b3d33b67e98
Reviewed-by: Marco Bubke <marco.bubke@qt.io>
This commit is contained in:
Ivan Donchevskii
2019-02-21 12:13:46 +01:00
parent 1a65acf639
commit c5e4d73431
2 changed files with 8 additions and 3 deletions

View File

@@ -357,8 +357,10 @@ TextEditor::Replacements ClangFormatBaseIndenter::replacements(QByteArray buffer
adjustFormatStyleForLineBreak(style, replacementsToKeep);
if (typedChar == QChar::Null) {
if (replacementsToKeep == ReplacementsToKeep::IndentAndBefore) {
buffer.insert(utf8Offset - 1, " //");
utf8Offset += 3;
if (utf8Offset > 0) {
buffer.insert(utf8Offset - 1, " //");
utf8Offset += 3;
}
utf8Length += forceIndentWithExtraText(buffer,
cursorPositionInEditor < 0
? endBlock

View File

@@ -84,7 +84,10 @@ Utils::optional<TabSettings> ClangFormatIndenter::tabSettings() const
int ClangFormatIndenter::lastSaveRevision() const
{
return qobject_cast<TextEditor::TextDocumentLayout *>(m_doc->documentLayout())->lastSaveRevision;
auto *layout = qobject_cast<TextEditor::TextDocumentLayout *>(m_doc->documentLayout());
if (!layout)
return 0;
return layout->lastSaveRevision;
}
bool ClangFormatIndenter::formatOnSave() const