From 30df84e177923f40326272d0b37aad98e8e42e9b Mon Sep 17 00:00:00 2001 From: David Schulz Date: Thu, 13 Jun 2019 10:21:04 +0200 Subject: [PATCH] TextEditor: directly create format range for result ... instead of just the text char format. Preparation for another way to set extra additional formats to the highlighter. Change-Id: I3635853ee8f4b432ffe48a4a4ebe0e790be603b1 Reviewed-by: Nikolai Kosjar --- .../texteditor/semantichighlighter.cpp | 23 +++++++++---------- 1 file changed, 11 insertions(+), 12 deletions(-) diff --git a/src/plugins/texteditor/semantichighlighter.cpp b/src/plugins/texteditor/semantichighlighter.cpp index e4aae5b612a..4a9e9b9dd4c 100644 --- a/src/plugins/texteditor/semantichighlighter.cpp +++ b/src/plugins/texteditor/semantichighlighter.cpp @@ -38,13 +38,17 @@ using namespace TextEditor::SemanticHighlighter; namespace { -QTextCharFormat textCharFormatForResult(const HighlightingResult &result, +QTextLayout::FormatRange rangeForResult(const HighlightingResult &result, const QHash &kindToFormat) { - if (result.useTextSyles) - return TextEditorSettings::fontSettings().toTextCharFormat(result.textStyles); - else - return kindToFormat.value(result.kind); + QTextLayout::FormatRange formatRange; + + formatRange.start = int(result.column) - 1; + formatRange.length = int(result.length); + formatRange.format = result.useTextSyles + ? TextEditorSettings::fontSettings().toTextCharFormat(result.textStyles) + : kindToFormat.value(result.kind); + return formatRange; } } @@ -95,14 +99,9 @@ void SemanticHighlighter::incrementalApplyExtraAdditionalFormats( QVector formats; formats.reserve(to - from); forever { - QTextLayout::FormatRange formatRange; - - formatRange.format = textCharFormatForResult(result, kindToFormat); - if (formatRange.format.isValid()) { - formatRange.start = int(result.column) - 1; - formatRange.length = int(result.length); + const QTextLayout::FormatRange formatRange = rangeForResult(result, kindToFormat); + if (formatRange.format.isValid()) formats.append(formatRange); - } ++i; if (i >= to)