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 <nikolai.kosjar@qt.io>
This commit is contained in:
David Schulz
2019-06-13 10:21:04 +02:00
parent 2eddd65596
commit 30df84e177

View File

@@ -38,13 +38,17 @@ using namespace TextEditor::SemanticHighlighter;
namespace {
QTextCharFormat textCharFormatForResult(const HighlightingResult &result,
QTextLayout::FormatRange rangeForResult(const HighlightingResult &result,
const QHash<int, QTextCharFormat> &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<QTextLayout::FormatRange> 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)