forked from qt-creator/qt-creator
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:
@@ -357,8 +357,10 @@ TextEditor::Replacements ClangFormatBaseIndenter::replacements(QByteArray buffer
|
|||||||
adjustFormatStyleForLineBreak(style, replacementsToKeep);
|
adjustFormatStyleForLineBreak(style, replacementsToKeep);
|
||||||
if (typedChar == QChar::Null) {
|
if (typedChar == QChar::Null) {
|
||||||
if (replacementsToKeep == ReplacementsToKeep::IndentAndBefore) {
|
if (replacementsToKeep == ReplacementsToKeep::IndentAndBefore) {
|
||||||
buffer.insert(utf8Offset - 1, " //");
|
if (utf8Offset > 0) {
|
||||||
utf8Offset += 3;
|
buffer.insert(utf8Offset - 1, " //");
|
||||||
|
utf8Offset += 3;
|
||||||
|
}
|
||||||
utf8Length += forceIndentWithExtraText(buffer,
|
utf8Length += forceIndentWithExtraText(buffer,
|
||||||
cursorPositionInEditor < 0
|
cursorPositionInEditor < 0
|
||||||
? endBlock
|
? endBlock
|
||||||
|
@@ -84,7 +84,10 @@ Utils::optional<TabSettings> ClangFormatIndenter::tabSettings() const
|
|||||||
|
|
||||||
int ClangFormatIndenter::lastSaveRevision() 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
|
bool ClangFormatIndenter::formatOnSave() const
|
||||||
|
Reference in New Issue
Block a user