diff --git a/src/plugins/cmakeprojectmanager/cmakeeditor.cpp b/src/plugins/cmakeprojectmanager/cmakeeditor.cpp index 873c5b5debe..fa19445743d 100644 --- a/src/plugins/cmakeprojectmanager/cmakeeditor.cpp +++ b/src/plugins/cmakeprojectmanager/cmakeeditor.cpp @@ -276,7 +276,7 @@ CMakeEditorFactory::CMakeEditorFactory(CMakeSettingsPage *settingsPage) setEditorCreator([]() { return new CMakeEditor; }); setEditorWidgetCreator([]() { return new CMakeEditorWidget; }); setDocumentCreator([]() { return new CMakeDocument; }); - setGenericSyntaxHighlighter(QLatin1String(Constants::CMAKEMIMETYPE)); + setGenericSyntaxHighlighterByName(QLatin1String("CMake")); setCommentStyle(Utils::CommentDefinition::HashStyle); setCodeFoldingSupported(true); diff --git a/src/plugins/texteditor/texteditor.cpp b/src/plugins/texteditor/texteditor.cpp index 0de6b93ee08..51a61203dfb 100644 --- a/src/plugins/texteditor/texteditor.cpp +++ b/src/plugins/texteditor/texteditor.cpp @@ -7377,6 +7377,20 @@ void TextEditorFactory::setGenericSyntaxHighlighter(const QString &mimeType) }; } +void TextEditorFactory::setGenericSyntaxHighlighterByName(const QString &name) +{ + d->m_syntaxHighlighterCreator = [this, name]() -> SyntaxHighlighter * { + TextEditor::Highlighter *highlighter = new TextEditor::Highlighter(); + QString definitionId = Manager::instance()->definitionIdByName(name); + if (!definitionId.isEmpty()) { + const QSharedPointer &definition = Manager::instance()->definition(definitionId); + if (!definition.isNull() && definition->isValid()) + highlighter->setDefaultContext(definition->initialContext()); + } + return highlighter; + }; +} + void TextEditorFactory::setAutoCompleterCreator(const AutoCompleterCreator &creator) { d->m_autoCompleterCreator = creator; diff --git a/src/plugins/texteditor/texteditor.h b/src/plugins/texteditor/texteditor.h index c364df2ff13..caee57de046 100644 --- a/src/plugins/texteditor/texteditor.h +++ b/src/plugins/texteditor/texteditor.h @@ -667,6 +667,7 @@ public: void setIndenterCreator(const IndenterCreator &creator); void setSyntaxHighlighterCreator(const SyntaxHighLighterCreator &creator); void setGenericSyntaxHighlighter(const QString &mimeType); + void setGenericSyntaxHighlighterByName(const QString &name); void setAutoCompleterCreator(const AutoCompleterCreator &creator); void setEditorActionHandlers(Core::Id contextId, uint optionalActions);