diff --git a/src/plugins/cmakeprojectmanager/cmakeeditor.cpp b/src/plugins/cmakeprojectmanager/cmakeeditor.cpp index 981dcf8d7d9..a6e1c54d29f 100644 --- a/src/plugins/cmakeprojectmanager/cmakeeditor.cpp +++ b/src/plugins/cmakeprojectmanager/cmakeeditor.cpp @@ -515,7 +515,7 @@ CMakeEditorFactory::CMakeEditorFactory() setEditorCreator([] { return new CMakeEditor; }); setEditorWidgetCreator([] { return new CMakeEditorWidget; }); setDocumentCreator(createCMakeDocument); - setIndenterCreator([](QTextDocument *doc) { return new CMakeIndenter(doc); }); + setIndenterCreator(createCMakeIndenter); setUseGenericHighlighter(true); setCommentDefinition(Utils::CommentDefinition::HashStyle); setCodeFoldingSupported(true); diff --git a/src/plugins/cmakeprojectmanager/cmakeindenter.cpp b/src/plugins/cmakeprojectmanager/cmakeindenter.cpp index e3e88212c57..fd65480e8af 100644 --- a/src/plugins/cmakeprojectmanager/cmakeindenter.cpp +++ b/src/plugins/cmakeprojectmanager/cmakeindenter.cpp @@ -5,9 +5,20 @@ namespace CMakeProjectManager::Internal { -CMakeIndenter::CMakeIndenter(QTextDocument *doc) - : TextEditor::TextIndenter(doc) -{} +class CMakeIndenter final : public TextEditor::TextIndenter +{ +public: + explicit CMakeIndenter(QTextDocument *doc) + : TextEditor::TextIndenter(doc) + {} + + bool isElectricCharacter(const QChar &ch) const final; + + int indentFor(const QTextBlock &block, + const TextEditor::TabSettings &tabSettings, + int cursorPositionInEditor = -1) final; +}; + bool CMakeIndenter::isElectricCharacter(const QChar &ch) const { @@ -44,6 +55,7 @@ static bool lineContainsFunction(const QString &line, const QString &function) } return false; } + static bool lineStartsBlock(const QString &line) { return lineContainsFunction(line, QStringLiteral("function")) || @@ -55,6 +67,7 @@ static bool lineStartsBlock(const QString &line) lineContainsFunction(line, QStringLiteral("else")) || lineContainsFunction(line, QStringLiteral("block")); } + static bool lineEndsBlock(const QString &line) { return lineContainsFunction(line, QStringLiteral("endfunction")) || @@ -66,6 +79,7 @@ static bool lineEndsBlock(const QString &line) lineContainsFunction(line, QStringLiteral("else")) || lineContainsFunction(line, QStringLiteral("endblock")); } + static bool lineIsEmpty(const QString &line) { for (const QChar &c : line) { @@ -112,4 +126,9 @@ int CMakeIndenter::indentFor(const QTextBlock &block, return qMax(0, indentation); } +TextEditor::Indenter *createCMakeIndenter(QTextDocument *doc) +{ + return new CMakeIndenter(doc); +} + } // CMakeProjectManager::Internal diff --git a/src/plugins/cmakeprojectmanager/cmakeindenter.h b/src/plugins/cmakeprojectmanager/cmakeindenter.h index 111a200d725..85a57bcbbbd 100644 --- a/src/plugins/cmakeprojectmanager/cmakeindenter.h +++ b/src/plugins/cmakeprojectmanager/cmakeindenter.h @@ -3,21 +3,10 @@ #pragma once -#include "cmake_global.h" - #include namespace CMakeProjectManager::Internal { -class CMAKE_EXPORT CMakeIndenter : public TextEditor::TextIndenter -{ -public: - explicit CMakeIndenter(QTextDocument *doc); - bool isElectricCharacter(const QChar &ch) const override; - - int indentFor(const QTextBlock &block, - const TextEditor::TabSettings &tabSettings, - int cursorPositionInEditor = -1) override; -}; +TextEditor::Indenter *createCMakeIndenter(QTextDocument *doc); } // CMakeProjectManager::Internal