forked from qt-creator/qt-creator
Utils: Move highlight function to textutils
Change-Id: I4c861ba8fa45bf5bf967903451a98c05bc4cb2ae Reviewed-by: hjk <hjk@qt.io>
This commit is contained in:
@@ -678,25 +678,4 @@ QString ansiColoredText(const QString &text, const QColor &color)
|
||||
return formatString.arg(color.red()).arg(color.green()).arg(color.blue()).arg(text);
|
||||
}
|
||||
|
||||
static HighlightCallback &codeHighlighter()
|
||||
{
|
||||
static HighlightCallback s_highlighter;
|
||||
return s_highlighter;
|
||||
}
|
||||
|
||||
QTextDocument *highlightCode(const QString &code, const QString &mimeType)
|
||||
{
|
||||
if (const auto highlighter = codeHighlighter())
|
||||
return highlighter(code, mimeType);
|
||||
|
||||
QTextDocument *doc = new QTextDocument;
|
||||
doc->setPlainText(code);
|
||||
return doc;
|
||||
}
|
||||
|
||||
void setCodeHighlighter(const HighlightCallback &highlighter)
|
||||
{
|
||||
codeHighlighter() = highlighter;
|
||||
}
|
||||
|
||||
} // namespace Utils
|
||||
|
@@ -141,8 +141,4 @@ private:
|
||||
|
||||
QTCREATOR_UTILS_EXPORT QString ansiColoredText(const QString &text, const QColor &color);
|
||||
|
||||
using HighlightCallback = std::function<QTextDocument *(const QString &, const QString &)>;
|
||||
QTCREATOR_UTILS_EXPORT QTextDocument *highlightCode(const QString &code, const QString &mimeType);
|
||||
QTCREATOR_UTILS_EXPORT void setCodeHighlighter(const HighlightCallback &highlighter);
|
||||
|
||||
} // namespace Utils
|
||||
|
@@ -293,4 +293,25 @@ QDebug &operator<<(QDebug &stream, const Position &pos)
|
||||
return stream;
|
||||
}
|
||||
|
||||
static HighlightCallback &codeHighlighter()
|
||||
{
|
||||
static HighlightCallback s_highlighter;
|
||||
return s_highlighter;
|
||||
}
|
||||
|
||||
QTextDocument *highlightCode(const QString &code, const QString &mimeType)
|
||||
{
|
||||
if (const auto highlighter = codeHighlighter())
|
||||
return highlighter(code, mimeType);
|
||||
|
||||
QTextDocument *doc = new QTextDocument;
|
||||
doc->setPlainText(code);
|
||||
return doc;
|
||||
}
|
||||
|
||||
void setCodeHighlighter(const HighlightCallback &highlighter)
|
||||
{
|
||||
codeHighlighter() = highlighter;
|
||||
}
|
||||
|
||||
} // namespace Utils::Text
|
||||
|
@@ -84,6 +84,10 @@ QTCREATOR_UTILS_EXPORT QString utf16LineTextInUtf8Buffer(const QByteArray &utf8B
|
||||
|
||||
QTCREATOR_UTILS_EXPORT QDebug &operator<<(QDebug &stream, const Position &pos);
|
||||
|
||||
using HighlightCallback = std::function<QTextDocument *(const QString &, const QString &)>;
|
||||
QTCREATOR_UTILS_EXPORT QTextDocument *highlightCode(const QString &code, const QString &mimeType);
|
||||
QTCREATOR_UTILS_EXPORT void setCodeHighlighter(const HighlightCallback &highlighter);
|
||||
|
||||
} // Text
|
||||
} // Utils
|
||||
|
||||
|
Reference in New Issue
Block a user