From 5ba10671daf2761db4defd825c859460d949616a Mon Sep 17 00:00:00 2001 From: David Schulz Date: Thu, 15 Jun 2023 13:28:33 +0200 Subject: [PATCH] CppEditor: fix highlighter tests amends 9091c994298f75ca76a9e1244236925320f60e15 Change-Id: Iaa64d51aa0dad1d63c88a51bfa55afa2367e65ed Reviewed-by: Christian Kandeler --- src/plugins/cppeditor/cpphighlighter.cpp | 5 +++-- src/plugins/texteditor/syntaxhighlighter.cpp | 7 +++++++ src/plugins/texteditor/syntaxhighlighter.h | 1 + 3 files changed, 11 insertions(+), 2 deletions(-) diff --git a/src/plugins/cppeditor/cpphighlighter.cpp b/src/plugins/cppeditor/cpphighlighter.cpp index f5ef94efdee..656173feee2 100644 --- a/src/plugins/cppeditor/cpphighlighter.cpp +++ b/src/plugins/cppeditor/cpphighlighter.cpp @@ -621,8 +621,9 @@ void CppHighlighterTest::test() const QChar c = m_doc.characterAt(pos); if (c == QChar::ParagraphSeparator) continue; - const QTextCharFormat expectedFormat = c.isSpace() - ? whitespacified(formatForStyle) : formatForStyle; + const QTextCharFormat expectedFormat = asSyntaxHighlight( + c.isSpace() ? whitespacified(formatForStyle) : formatForStyle); + const QTextCharFormat actualFormat = getActualFormat(pos); if (actualFormat != expectedFormat) { int posLine; diff --git a/src/plugins/texteditor/syntaxhighlighter.cpp b/src/plugins/texteditor/syntaxhighlighter.cpp index 21db8c0cd32..d8b39a5c2c2 100644 --- a/src/plugins/texteditor/syntaxhighlighter.cpp +++ b/src/plugins/texteditor/syntaxhighlighter.cpp @@ -869,6 +869,13 @@ QTextCharFormat SyntaxHighlighter::whitespacified(const QTextCharFormat &fmt) return format; } +QTextCharFormat SyntaxHighlighter::asSyntaxHighlight(const QTextCharFormat &fmt) +{ + QTextCharFormat format = fmt; + format.setProperty(SyntaxHighlight, true); + return format; +} + void SyntaxHighlighter::highlightBlock(const QString &text) { formatSpaces(text); diff --git a/src/plugins/texteditor/syntaxhighlighter.h b/src/plugins/texteditor/syntaxhighlighter.h index 1b66e2ff56a..856aef72487 100644 --- a/src/plugins/texteditor/syntaxhighlighter.h +++ b/src/plugins/texteditor/syntaxhighlighter.h @@ -62,6 +62,7 @@ protected: void setTextFormatCategories(int count, std::function formatMapping); QTextCharFormat formatForCategory(int categoryIndex) const; QTextCharFormat whitespacified(const QTextCharFormat &fmt); + QTextCharFormat asSyntaxHighlight(const QTextCharFormat &fmt); // implement in subclasses // default implementation highlights whitespace