From d8a75d48a303ca0de50c47f1e592e5e56be916d2 Mon Sep 17 00:00:00 2001 From: Marcus Tillmanns Date: Tue, 17 Oct 2023 09:23:25 +0200 Subject: [PATCH] TextEditor: Add selecting highlighter by name Change-Id: I5c706dd151173bf08c5fbd4dacbf6e5d6416b87b Reviewed-by: David Schulz --- src/plugins/texteditor/highlighter.h | 3 ++- src/plugins/texteditor/texteditor.cpp | 6 ++++++ src/plugins/texteditor/texteditor.h | 4 ++++ 3 files changed, 12 insertions(+), 1 deletion(-) diff --git a/src/plugins/texteditor/highlighter.h b/src/plugins/texteditor/highlighter.h index 0183c9c171e..b3f10d0671d 100644 --- a/src/plugins/texteditor/highlighter.h +++ b/src/plugins/texteditor/highlighter.h @@ -13,7 +13,8 @@ namespace TextEditor { class TextDocument; -class Highlighter : public SyntaxHighlighter, public KSyntaxHighlighting::AbstractHighlighter +class TEXTEDITOR_EXPORT Highlighter : public SyntaxHighlighter, + public KSyntaxHighlighting::AbstractHighlighter { Q_OBJECT Q_INTERFACES(KSyntaxHighlighting::AbstractHighlighter) diff --git a/src/plugins/texteditor/texteditor.cpp b/src/plugins/texteditor/texteditor.cpp index c5b73125d5f..70265e14a47 100644 --- a/src/plugins/texteditor/texteditor.cpp +++ b/src/plugins/texteditor/texteditor.cpp @@ -9068,6 +9068,12 @@ void TextEditorWidget::configureGenericHighlighter(const Utils::MimeType &mimeTy d->removeSyntaxInfoBar(); } +void TextEditorWidget::configureGenericHighlighter(const Highlighter::Definition &definition) +{ + d->configureGenericHighlighter(definition); + d->removeSyntaxInfoBar(); +} + int TextEditorWidget::blockNumberForVisibleRow(int row) const { QTextBlock block = blockForVisibleRow(row); diff --git a/src/plugins/texteditor/texteditor.h b/src/plugins/texteditor/texteditor.h index 6f67fe67748..2af45826368 100644 --- a/src/plugins/texteditor/texteditor.h +++ b/src/plugins/texteditor/texteditor.h @@ -6,6 +6,7 @@ #include "texteditor_global.h" #include "codeassist/assistenums.h" +#include "highlighter.h" #include "indenter.h" #include "refactoroverlay.h" #include "snippets/snippetparser.h" @@ -453,6 +454,9 @@ public: /// Overwrite the current highlighter with a new generic highlighter based on the given mimetype void configureGenericHighlighter(const Utils::MimeType &mimeType); + /// Overwrite the current highlighter with a new generic highlighter based on the given definition + void configureGenericHighlighter(const Highlighter::Definition &definition); + Q_INVOKABLE void inSnippetMode(bool *active); // Used by FakeVim. /*! Returns the document line number for the visible \a row.