forked from qt-creator/qt-creator
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:
@@ -38,13 +38,17 @@ using namespace TextEditor::SemanticHighlighter;
|
|||||||
|
|
||||||
namespace {
|
namespace {
|
||||||
|
|
||||||
QTextCharFormat textCharFormatForResult(const HighlightingResult &result,
|
QTextLayout::FormatRange rangeForResult(const HighlightingResult &result,
|
||||||
const QHash<int, QTextCharFormat> &kindToFormat)
|
const QHash<int, QTextCharFormat> &kindToFormat)
|
||||||
{
|
{
|
||||||
if (result.useTextSyles)
|
QTextLayout::FormatRange formatRange;
|
||||||
return TextEditorSettings::fontSettings().toTextCharFormat(result.textStyles);
|
|
||||||
else
|
formatRange.start = int(result.column) - 1;
|
||||||
return kindToFormat.value(result.kind);
|
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;
|
QVector<QTextLayout::FormatRange> formats;
|
||||||
formats.reserve(to - from);
|
formats.reserve(to - from);
|
||||||
forever {
|
forever {
|
||||||
QTextLayout::FormatRange formatRange;
|
const QTextLayout::FormatRange formatRange = rangeForResult(result, kindToFormat);
|
||||||
|
if (formatRange.format.isValid())
|
||||||
formatRange.format = textCharFormatForResult(result, kindToFormat);
|
|
||||||
if (formatRange.format.isValid()) {
|
|
||||||
formatRange.start = int(result.column) - 1;
|
|
||||||
formatRange.length = int(result.length);
|
|
||||||
formats.append(formatRange);
|
formats.append(formatRange);
|
||||||
}
|
|
||||||
|
|
||||||
++i;
|
++i;
|
||||||
if (i >= to)
|
if (i >= to)
|
||||||
|
Reference in New Issue
Block a user