forked from qt-creator/qt-creator
Simplify text format handling in syntax highlighters
Pass the mapping from custom enum to text style in form of a function, which then can use a switch which is checked by compilers, and avoids the need to lookup a different enum somewhere else to find out what the mapping actually is. That mapping is cached to keep performance as before. Also, most highlighters created an enum just for the purpose of mapping to text styles, basically creating duplicated subsets of text style like enums everywhere. Instead provide a default, identity mapping from text styles to text styles. Change-Id: I2ea1ca702b99e36b8742dfda510b1b2753f0a1c2 Reviewed-by: David Schulz <david.schulz@qt.io>
This commit is contained in:
@@ -153,6 +153,21 @@ decltype(auto) equal(R S::*member, T value)
|
|||||||
return std::bind<bool>(std::equal_to<T>(), value, std::bind(member, std::placeholders::_1));
|
return std::bind<bool>(std::equal_to<T>(), value, std::bind(member, std::placeholders::_1));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//////////////////
|
||||||
|
// max element
|
||||||
|
//////////////////
|
||||||
|
|
||||||
|
template<typename T>
|
||||||
|
typename T::value_type maxElementOr(const T &container, typename T::value_type other)
|
||||||
|
{
|
||||||
|
typename T::const_iterator end = container.end();
|
||||||
|
typename T::const_iterator begin = container.begin();
|
||||||
|
|
||||||
|
typename T::const_iterator it = std::max_element(begin, end);
|
||||||
|
if (it == end)
|
||||||
|
return other;
|
||||||
|
return *it;
|
||||||
|
}
|
||||||
|
|
||||||
//////////////////
|
//////////////////
|
||||||
// transform
|
// transform
|
||||||
|
|||||||
@@ -33,21 +33,5 @@ enum FileType {
|
|||||||
Source
|
Source
|
||||||
};
|
};
|
||||||
|
|
||||||
enum CppFormats {
|
|
||||||
CppNumberFormat,
|
|
||||||
CppStringFormat,
|
|
||||||
CppTypeFormat,
|
|
||||||
CppKeywordFormat,
|
|
||||||
CppPrimitiveTypeFormat,
|
|
||||||
CppOperatorFormat,
|
|
||||||
CppPreprocessorFormat,
|
|
||||||
CppLabelFormat,
|
|
||||||
CppCommentFormat,
|
|
||||||
CppDoxygenCommentFormat,
|
|
||||||
CppDoxygenTagFormat,
|
|
||||||
CppVisualWhitespace,
|
|
||||||
NumCppFormats
|
|
||||||
};
|
|
||||||
|
|
||||||
} // namespace Internal
|
} // namespace Internal
|
||||||
} // namespace CppEditor
|
} // namespace CppEditor
|
||||||
|
|||||||
@@ -42,21 +42,7 @@ using namespace CPlusPlus;
|
|||||||
CppHighlighter::CppHighlighter(QTextDocument *document) :
|
CppHighlighter::CppHighlighter(QTextDocument *document) :
|
||||||
SyntaxHighlighter(document)
|
SyntaxHighlighter(document)
|
||||||
{
|
{
|
||||||
static const QVector<TextStyle> categories({
|
setDefaultTextFormatCategories();
|
||||||
C_NUMBER,
|
|
||||||
C_STRING,
|
|
||||||
C_TYPE,
|
|
||||||
C_KEYWORD,
|
|
||||||
C_PRIMITIVE_TYPE,
|
|
||||||
C_OPERATOR,
|
|
||||||
C_PREPROCESSOR,
|
|
||||||
C_LABEL,
|
|
||||||
C_COMMENT,
|
|
||||||
C_DOXYGEN_COMMENT,
|
|
||||||
C_DOXYGEN_TAG,
|
|
||||||
C_VISUAL_WHITESPACE
|
|
||||||
});
|
|
||||||
setTextFormatCategories(categories);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void CppHighlighter::highlightBlock(const QString &text)
|
void CppHighlighter::highlightBlock(const QString &text)
|
||||||
@@ -90,11 +76,11 @@ void CppHighlighter::highlightBlock(const QString &text)
|
|||||||
TextDocumentLayout::clearParentheses(currentBlock());
|
TextDocumentLayout::clearParentheses(currentBlock());
|
||||||
if (text.length()) {// the empty line can still contain whitespace
|
if (text.length()) {// the empty line can still contain whitespace
|
||||||
if (initialLexerState == T_COMMENT)
|
if (initialLexerState == T_COMMENT)
|
||||||
highlightLine(text, 0, text.length(), formatForCategory(CppCommentFormat));
|
highlightLine(text, 0, text.length(), formatForCategory(C_COMMENT));
|
||||||
else if (initialLexerState == T_DOXY_COMMENT)
|
else if (initialLexerState == T_DOXY_COMMENT)
|
||||||
highlightLine(text, 0, text.length(), formatForCategory(CppDoxygenCommentFormat));
|
highlightLine(text, 0, text.length(), formatForCategory(C_DOXYGEN_COMMENT));
|
||||||
else
|
else
|
||||||
setFormat(0, text.length(), formatForCategory(CppVisualWhitespace));
|
setFormat(0, text.length(), formatForCategory(C_VISUAL_WHITESPACE));
|
||||||
}
|
}
|
||||||
TextDocumentLayout::setFoldingIndent(currentBlock(), foldingIndent);
|
TextDocumentLayout::setFoldingIndent(currentBlock(), foldingIndent);
|
||||||
return;
|
return;
|
||||||
@@ -121,7 +107,7 @@ void CppHighlighter::highlightBlock(const QString &text)
|
|||||||
if (previousTokenEnd != tk.utf16charsBegin()) {
|
if (previousTokenEnd != tk.utf16charsBegin()) {
|
||||||
setFormat(previousTokenEnd,
|
setFormat(previousTokenEnd,
|
||||||
tk.utf16charsBegin() - previousTokenEnd,
|
tk.utf16charsBegin() - previousTokenEnd,
|
||||||
formatForCategory(CppVisualWhitespace));
|
formatForCategory(C_VISUAL_WHITESPACE));
|
||||||
}
|
}
|
||||||
|
|
||||||
if (tk.is(T_LPAREN) || tk.is(T_LBRACE) || tk.is(T_LBRACKET)) {
|
if (tk.is(T_LPAREN) || tk.is(T_LBRACE) || tk.is(T_LBRACKET)) {
|
||||||
@@ -162,12 +148,12 @@ void CppHighlighter::highlightBlock(const QString &text)
|
|||||||
|
|
||||||
if (i == 0 && tk.is(T_POUND)) {
|
if (i == 0 && tk.is(T_POUND)) {
|
||||||
highlightLine(text, tk.utf16charsBegin(), tk.utf16chars(),
|
highlightLine(text, tk.utf16charsBegin(), tk.utf16chars(),
|
||||||
formatForCategory(CppPreprocessorFormat));
|
formatForCategory(C_PREPROCESSOR));
|
||||||
expectPreprocessorKeyword = true;
|
expectPreprocessorKeyword = true;
|
||||||
} else if (highlightCurrentWordAsPreprocessor
|
} else if (highlightCurrentWordAsPreprocessor
|
||||||
&& (tk.isKeyword() || tk.is(T_IDENTIFIER))
|
&& (tk.isKeyword() || tk.is(T_IDENTIFIER))
|
||||||
&& isPPKeyword(text.midRef(tk.utf16charsBegin(), tk.utf16chars()))) {
|
&& isPPKeyword(text.midRef(tk.utf16charsBegin(), tk.utf16chars()))) {
|
||||||
setFormat(tk.utf16charsBegin(), tk.utf16chars(), formatForCategory(CppPreprocessorFormat));
|
setFormat(tk.utf16charsBegin(), tk.utf16chars(), formatForCategory(C_PREPROCESSOR));
|
||||||
const QStringRef ppKeyword = text.midRef(tk.utf16charsBegin(), tk.utf16chars());
|
const QStringRef ppKeyword = text.midRef(tk.utf16charsBegin(), tk.utf16chars());
|
||||||
if (ppKeyword == QLatin1String("error")
|
if (ppKeyword == QLatin1String("error")
|
||||||
|| ppKeyword == QLatin1String("warning")
|
|| ppKeyword == QLatin1String("warning")
|
||||||
@@ -176,14 +162,14 @@ void CppHighlighter::highlightBlock(const QString &text)
|
|||||||
}
|
}
|
||||||
|
|
||||||
} else if (tk.is(T_NUMERIC_LITERAL)) {
|
} else if (tk.is(T_NUMERIC_LITERAL)) {
|
||||||
setFormat(tk.utf16charsBegin(), tk.utf16chars(), formatForCategory(CppNumberFormat));
|
setFormat(tk.utf16charsBegin(), tk.utf16chars(), formatForCategory(C_NUMBER));
|
||||||
} else if (tk.isStringLiteral() || tk.isCharLiteral()) {
|
} else if (tk.isStringLiteral() || tk.isCharLiteral()) {
|
||||||
highlightLine(text, tk.utf16charsBegin(), tk.utf16chars(), formatForCategory(CppStringFormat));
|
highlightLine(text, tk.utf16charsBegin(), tk.utf16chars(), formatForCategory(C_STRING));
|
||||||
} else if (tk.isComment()) {
|
} else if (tk.isComment()) {
|
||||||
const int startPosition = initialLexerState ? previousTokenEnd : tk.utf16charsBegin();
|
const int startPosition = initialLexerState ? previousTokenEnd : tk.utf16charsBegin();
|
||||||
if (tk.is(T_COMMENT) || tk.is(T_CPP_COMMENT)) {
|
if (tk.is(T_COMMENT) || tk.is(T_CPP_COMMENT)) {
|
||||||
highlightLine(text, startPosition, tk.utf16charsEnd() - startPosition,
|
highlightLine(text, startPosition, tk.utf16charsEnd() - startPosition,
|
||||||
formatForCategory(CppCommentFormat));
|
formatForCategory(C_COMMENT));
|
||||||
}
|
}
|
||||||
|
|
||||||
else // a doxygen comment
|
else // a doxygen comment
|
||||||
@@ -211,14 +197,14 @@ void CppHighlighter::highlightBlock(const QString &text)
|
|||||||
|| (m_languageFeatures.qtKeywordsEnabled
|
|| (m_languageFeatures.qtKeywordsEnabled
|
||||||
&& CppTools::isQtKeyword(text.midRef(tk.utf16charsBegin(), tk.utf16chars())))
|
&& CppTools::isQtKeyword(text.midRef(tk.utf16charsBegin(), tk.utf16chars())))
|
||||||
|| (m_languageFeatures.objCEnabled && tk.isObjCAtKeyword())) {
|
|| (m_languageFeatures.objCEnabled && tk.isObjCAtKeyword())) {
|
||||||
setFormat(tk.utf16charsBegin(), tk.utf16chars(), formatForCategory(CppKeywordFormat));
|
setFormat(tk.utf16charsBegin(), tk.utf16chars(), formatForCategory(C_KEYWORD));
|
||||||
} else if (tk.isPrimitiveType()) {
|
} else if (tk.isPrimitiveType()) {
|
||||||
setFormat(tk.utf16charsBegin(), tk.utf16chars(),
|
setFormat(tk.utf16charsBegin(), tk.utf16chars(),
|
||||||
formatForCategory(CppPrimitiveTypeFormat));
|
formatForCategory(C_PRIMITIVE_TYPE));
|
||||||
} else if (tk.isOperator()) {
|
} else if (tk.isOperator()) {
|
||||||
setFormat(tk.utf16charsBegin(), tk.utf16chars(), formatForCategory(CppOperatorFormat));
|
setFormat(tk.utf16charsBegin(), tk.utf16chars(), formatForCategory(C_OPERATOR));
|
||||||
} else if (i == 0 && tokens.size() > 1 && tk.is(T_IDENTIFIER) && tokens.at(1).is(T_COLON)) {
|
} else if (i == 0 && tokens.size() > 1 && tk.is(T_IDENTIFIER) && tokens.at(1).is(T_COLON)) {
|
||||||
setFormat(tk.utf16charsBegin(), tk.utf16chars(), formatForCategory(CppLabelFormat));
|
setFormat(tk.utf16charsBegin(), tk.utf16chars(), formatForCategory(C_LABEL));
|
||||||
} else if (tk.is(T_IDENTIFIER)) {
|
} else if (tk.is(T_IDENTIFIER)) {
|
||||||
highlightWord(text.midRef(tk.utf16charsBegin(), tk.utf16chars()), tk.utf16charsBegin(),
|
highlightWord(text.midRef(tk.utf16charsBegin(), tk.utf16chars()), tk.utf16charsBegin(),
|
||||||
tk.utf16chars());
|
tk.utf16chars());
|
||||||
@@ -228,7 +214,7 @@ void CppHighlighter::highlightBlock(const QString &text)
|
|||||||
// mark the trailing white spaces
|
// mark the trailing white spaces
|
||||||
const int lastTokenEnd = tokens.last().utf16charsEnd();
|
const int lastTokenEnd = tokens.last().utf16charsEnd();
|
||||||
if (text.length() > lastTokenEnd)
|
if (text.length() > lastTokenEnd)
|
||||||
highlightLine(text, lastTokenEnd, text.length() - lastTokenEnd, formatForCategory(CppVisualWhitespace));
|
highlightLine(text, lastTokenEnd, text.length() - lastTokenEnd, formatForCategory(C_VISUAL_WHITESPACE));
|
||||||
|
|
||||||
if (!initialLexerState && lexerState && !tokens.isEmpty()) {
|
if (!initialLexerState && lexerState && !tokens.isEmpty()) {
|
||||||
const Token &lastToken = tokens.last();
|
const Token &lastToken = tokens.last();
|
||||||
@@ -360,7 +346,7 @@ bool CppHighlighter::isPPKeyword(const QStringRef &text) const
|
|||||||
void CppHighlighter::highlightLine(const QString &text, int position, int length,
|
void CppHighlighter::highlightLine(const QString &text, int position, int length,
|
||||||
const QTextCharFormat &format)
|
const QTextCharFormat &format)
|
||||||
{
|
{
|
||||||
QTextCharFormat visualSpaceFormat = formatForCategory(CppVisualWhitespace);
|
QTextCharFormat visualSpaceFormat = formatForCategory(C_VISUAL_WHITESPACE);
|
||||||
visualSpaceFormat.setBackground(format.background());
|
visualSpaceFormat.setBackground(format.background());
|
||||||
|
|
||||||
const int end = position + length;
|
const int end = position + length;
|
||||||
@@ -394,7 +380,7 @@ void CppHighlighter::highlightWord(QStringRef word, int position, int length)
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
setFormat(position, length, formatForCategory(CppTypeFormat));
|
setFormat(position, length, formatForCategory(C_TYPE));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -406,8 +392,8 @@ void CppHighlighter::highlightDoxygenComment(const QString &text, int position,
|
|||||||
const QChar *uc = text.unicode();
|
const QChar *uc = text.unicode();
|
||||||
const QChar *it = uc + position;
|
const QChar *it = uc + position;
|
||||||
|
|
||||||
const QTextCharFormat &format = formatForCategory(CppDoxygenCommentFormat);
|
const QTextCharFormat &format = formatForCategory(C_DOXYGEN_COMMENT);
|
||||||
const QTextCharFormat &kwFormat = formatForCategory(CppDoxygenTagFormat);
|
const QTextCharFormat &kwFormat = formatForCategory(C_DOXYGEN_TAG);
|
||||||
|
|
||||||
while (!it->isNull()) {
|
while (!it->isNull()) {
|
||||||
if (it->unicode() == QLatin1Char('\\') ||
|
if (it->unicode() == QLatin1Char('\\') ||
|
||||||
|
|||||||
@@ -38,9 +38,7 @@ static const char CHANGE_PATTERN[] = "\\b[a-f0-9]{7,40}\\b";
|
|||||||
GitSubmitHighlighter::GitSubmitHighlighter(QTextEdit * parent) :
|
GitSubmitHighlighter::GitSubmitHighlighter(QTextEdit * parent) :
|
||||||
TextEditor::SyntaxHighlighter(parent)
|
TextEditor::SyntaxHighlighter(parent)
|
||||||
{
|
{
|
||||||
static const QVector<TextEditor::TextStyle> categories({TextEditor::C_COMMENT});
|
setDefaultTextFormatCategories();
|
||||||
|
|
||||||
setTextFormatCategories(categories);
|
|
||||||
m_keywordPattern.setPattern("^[\\w-]+:");
|
m_keywordPattern.setPattern("^[\\w-]+:");
|
||||||
m_hashChar = '#';
|
m_hashChar = '#';
|
||||||
QTC_CHECK(m_keywordPattern.isValid());
|
QTC_CHECK(m_keywordPattern.isValid());
|
||||||
@@ -56,7 +54,7 @@ void GitSubmitHighlighter::highlightBlock(const QString &text)
|
|||||||
setCurrentBlockState(state);
|
setCurrentBlockState(state);
|
||||||
return;
|
return;
|
||||||
} else if (text.startsWith(m_hashChar)) {
|
} else if (text.startsWith(m_hashChar)) {
|
||||||
setFormat(0, text.size(), formatForCategory(Format_Comment));
|
setFormat(0, text.size(), formatForCategory(TextEditor::C_COMMENT));
|
||||||
setCurrentBlockState(state);
|
setCurrentBlockState(state);
|
||||||
return;
|
return;
|
||||||
} else if (state == None) {
|
} else if (state == None) {
|
||||||
@@ -92,23 +90,34 @@ GitRebaseHighlighter::RebaseAction::RebaseAction(const QString ®exp,
|
|||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static TextEditor::TextStyle styleForFormat(int format)
|
||||||
|
{
|
||||||
|
using namespace TextEditor;
|
||||||
|
const auto f = Format(format);
|
||||||
|
switch (f) {
|
||||||
|
case Format_Comment: return C_COMMENT;
|
||||||
|
case Format_Change: return C_DOXYGEN_COMMENT;
|
||||||
|
case Format_Description: return C_STRING;
|
||||||
|
case Format_Pick: return C_KEYWORD;
|
||||||
|
case Format_Reword: return C_FIELD;
|
||||||
|
case Format_Edit: return C_TYPE;
|
||||||
|
case Format_Squash: return C_ENUMERATION;
|
||||||
|
case Format_Fixup: return C_NUMBER;
|
||||||
|
case Format_Exec: return C_LABEL;
|
||||||
|
case Format_Count:
|
||||||
|
QTC_CHECK(false); // should never get here
|
||||||
|
return C_TEXT;
|
||||||
|
}
|
||||||
|
QTC_CHECK(false); // should never get here
|
||||||
|
return C_TEXT;
|
||||||
|
}
|
||||||
|
|
||||||
GitRebaseHighlighter::GitRebaseHighlighter(QTextDocument *parent) :
|
GitRebaseHighlighter::GitRebaseHighlighter(QTextDocument *parent) :
|
||||||
TextEditor::SyntaxHighlighter(parent),
|
TextEditor::SyntaxHighlighter(parent),
|
||||||
m_hashChar('#'),
|
m_hashChar('#'),
|
||||||
m_changeNumberPattern(CHANGE_PATTERN)
|
m_changeNumberPattern(CHANGE_PATTERN)
|
||||||
{
|
{
|
||||||
static const QVector<TextEditor::TextStyle> categories({
|
setTextFormatCategories(Format_Count, styleForFormat);
|
||||||
TextEditor::C_COMMENT,
|
|
||||||
TextEditor::C_DOXYGEN_COMMENT,
|
|
||||||
TextEditor::C_STRING,
|
|
||||||
TextEditor::C_KEYWORD,
|
|
||||||
TextEditor::C_FIELD,
|
|
||||||
TextEditor::C_TYPE,
|
|
||||||
TextEditor::C_ENUMERATION,
|
|
||||||
TextEditor::C_NUMBER,
|
|
||||||
TextEditor::C_LABEL
|
|
||||||
});
|
|
||||||
setTextFormatCategories(categories);
|
|
||||||
|
|
||||||
m_actions << RebaseAction("^(p|pick)\\b", Format_Pick);
|
m_actions << RebaseAction("^(p|pick)\\b", Format_Pick);
|
||||||
m_actions << RebaseAction("^(r|reword)\\b", Format_Reword);
|
m_actions << RebaseAction("^(r|reword)\\b", Format_Reword);
|
||||||
|
|||||||
@@ -41,7 +41,8 @@ enum Format {
|
|||||||
Format_Edit,
|
Format_Edit,
|
||||||
Format_Squash,
|
Format_Squash,
|
||||||
Format_Fixup,
|
Format_Fixup,
|
||||||
Format_Exec
|
Format_Exec,
|
||||||
|
Format_Count
|
||||||
};
|
};
|
||||||
|
|
||||||
// Highlighter for git submit messages. Make the first line bold, indicates
|
// Highlighter for git submit messages. Make the first line bold, indicates
|
||||||
|
|||||||
@@ -34,26 +34,14 @@
|
|||||||
|
|
||||||
using namespace TextEditor;
|
using namespace TextEditor;
|
||||||
|
|
||||||
|
const TextStyle GLSLReservedKeyword = C_REMOVED_LINE;
|
||||||
|
|
||||||
namespace GlslEditor {
|
namespace GlslEditor {
|
||||||
namespace Internal {
|
namespace Internal {
|
||||||
|
|
||||||
GlslHighlighter::GlslHighlighter()
|
GlslHighlighter::GlslHighlighter()
|
||||||
{
|
{
|
||||||
static const QVector<TextStyle> categories({
|
setDefaultTextFormatCategories();
|
||||||
C_NUMBER,
|
|
||||||
C_STRING,
|
|
||||||
C_TYPE,
|
|
||||||
C_KEYWORD,
|
|
||||||
C_OPERATOR,
|
|
||||||
C_PREPROCESSOR,
|
|
||||||
C_LABEL,
|
|
||||||
C_COMMENT,
|
|
||||||
C_DOXYGEN_COMMENT,
|
|
||||||
C_DOXYGEN_TAG,
|
|
||||||
C_VISUAL_WHITESPACE,
|
|
||||||
C_REMOVED_LINE
|
|
||||||
});
|
|
||||||
setTextFormatCategories(categories);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void GlslHighlighter::highlightBlock(const QString &text)
|
void GlslHighlighter::highlightBlock(const QString &text)
|
||||||
@@ -99,7 +87,7 @@ void GlslHighlighter::highlightBlock(const QString &text)
|
|||||||
setCurrentBlockState(previousState);
|
setCurrentBlockState(previousState);
|
||||||
TextDocumentLayout::clearParentheses(currentBlock());
|
TextDocumentLayout::clearParentheses(currentBlock());
|
||||||
if (text.length()) // the empty line can still contain whitespace
|
if (text.length()) // the empty line can still contain whitespace
|
||||||
setFormat(0, text.length(), formatForCategory(GLSLVisualWhitespace));
|
setFormat(0, text.length(), formatForCategory(C_VISUAL_WHITESPACE));
|
||||||
TextDocumentLayout::setFoldingIndent(currentBlock(), foldingIndent);
|
TextDocumentLayout::setFoldingIndent(currentBlock(), foldingIndent);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@@ -123,7 +111,7 @@ void GlslHighlighter::highlightBlock(const QString &text)
|
|||||||
|
|
||||||
if (previousTokenEnd != tk.begin()) {
|
if (previousTokenEnd != tk.begin()) {
|
||||||
setFormat(previousTokenEnd, tk.begin() - previousTokenEnd,
|
setFormat(previousTokenEnd, tk.begin() - previousTokenEnd,
|
||||||
formatForCategory(GLSLVisualWhitespace));
|
formatForCategory(C_VISUAL_WHITESPACE));
|
||||||
}
|
}
|
||||||
|
|
||||||
if (tk.is(GLSL::Parser::T_LEFT_PAREN) || tk.is(GLSL::Parser::T_LEFT_BRACE) || tk.is(GLSL::Parser::T_LEFT_BRACKET)) {
|
if (tk.is(GLSL::Parser::T_LEFT_PAREN) || tk.is(GLSL::Parser::T_LEFT_BRACE) || tk.is(GLSL::Parser::T_LEFT_BRACKET)) {
|
||||||
@@ -160,17 +148,17 @@ void GlslHighlighter::highlightBlock(const QString &text)
|
|||||||
highlightAsPreprocessor = false;
|
highlightAsPreprocessor = false;
|
||||||
|
|
||||||
if (false /* && i == 0 && tk.is(GLSL::Parser::T_POUND)*/) {
|
if (false /* && i == 0 && tk.is(GLSL::Parser::T_POUND)*/) {
|
||||||
highlightLine(text, tk.begin(), tk.length, formatForCategory(GLSLPreprocessorFormat));
|
highlightLine(text, tk.begin(), tk.length, formatForCategory(C_PREPROCESSOR));
|
||||||
highlightAsPreprocessor = true;
|
highlightAsPreprocessor = true;
|
||||||
|
|
||||||
} else if (highlightCurrentWordAsPreprocessor && isPPKeyword(text.midRef(tk.begin(), tk.length))) {
|
} else if (highlightCurrentWordAsPreprocessor && isPPKeyword(text.midRef(tk.begin(), tk.length))) {
|
||||||
setFormat(tk.begin(), tk.length, formatForCategory(GLSLPreprocessorFormat));
|
setFormat(tk.begin(), tk.length, formatForCategory(C_PREPROCESSOR));
|
||||||
|
|
||||||
} else if (tk.is(GLSL::Parser::T_NUMBER)) {
|
} else if (tk.is(GLSL::Parser::T_NUMBER)) {
|
||||||
setFormat(tk.begin(), tk.length, formatForCategory(GLSLNumberFormat));
|
setFormat(tk.begin(), tk.length, formatForCategory(C_NUMBER));
|
||||||
|
|
||||||
} else if (tk.is(GLSL::Parser::T_COMMENT)) {
|
} else if (tk.is(GLSL::Parser::T_COMMENT)) {
|
||||||
highlightLine(text, tk.begin(), tk.length, formatForCategory(GLSLCommentFormat));
|
highlightLine(text, tk.begin(), tk.length, formatForCategory(C_COMMENT));
|
||||||
|
|
||||||
// we need to insert a close comment parenthesis, if
|
// we need to insert a close comment parenthesis, if
|
||||||
// - the line starts in a C Comment (initalState != 0)
|
// - the line starts in a C Comment (initalState != 0)
|
||||||
@@ -195,7 +183,7 @@ void GlslHighlighter::highlightBlock(const QString &text)
|
|||||||
if (kind == GLSL::Parser::T_RESERVED)
|
if (kind == GLSL::Parser::T_RESERVED)
|
||||||
setFormat(tk.position, tk.length, formatForCategory(GLSLReservedKeyword));
|
setFormat(tk.position, tk.length, formatForCategory(GLSLReservedKeyword));
|
||||||
else if (kind != GLSL::Parser::T_IDENTIFIER)
|
else if (kind != GLSL::Parser::T_IDENTIFIER)
|
||||||
setFormat(tk.position, tk.length, formatForCategory(GLSLKeywordFormat));
|
setFormat(tk.position, tk.length, formatForCategory(C_KEYWORD));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -248,7 +236,7 @@ void GlslHighlighter::highlightBlock(const QString &text)
|
|||||||
void GlslHighlighter::highlightLine(const QString &text, int position, int length,
|
void GlslHighlighter::highlightLine(const QString &text, int position, int length,
|
||||||
const QTextCharFormat &format)
|
const QTextCharFormat &format)
|
||||||
{
|
{
|
||||||
const QTextCharFormat visualSpaceFormat = formatForCategory(GLSLVisualWhitespace);
|
const QTextCharFormat visualSpaceFormat = formatForCategory(C_VISUAL_WHITESPACE);
|
||||||
|
|
||||||
const int end = position + length;
|
const int end = position + length;
|
||||||
int index = position;
|
int index = position;
|
||||||
|
|||||||
@@ -35,22 +35,6 @@ class GlslHighlighter : public TextEditor::SyntaxHighlighter
|
|||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
|
|
||||||
public:
|
public:
|
||||||
enum Formats {
|
|
||||||
GLSLNumberFormat,
|
|
||||||
GLSLStringFormat,
|
|
||||||
GLSLTypeFormat,
|
|
||||||
GLSLKeywordFormat,
|
|
||||||
GLSLOperatorFormat,
|
|
||||||
GLSLPreprocessorFormat,
|
|
||||||
GLSLLabelFormat,
|
|
||||||
GLSLCommentFormat,
|
|
||||||
GLSLDoxygenCommentFormat,
|
|
||||||
GLSLDoxygenTagFormat,
|
|
||||||
GLSLVisualWhitespace,
|
|
||||||
GLSLReservedKeyword,
|
|
||||||
NumGLSLFormats
|
|
||||||
};
|
|
||||||
|
|
||||||
GlslHighlighter();
|
GlslHighlighter();
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
|
|||||||
@@ -52,7 +52,6 @@ public:
|
|||||||
|
|
||||||
private:
|
private:
|
||||||
enum State { None = -1, Header, Other };
|
enum State { None = -1, Header, Other };
|
||||||
enum Format { Format_Comment };
|
|
||||||
QRegExp m_keywordPattern;
|
QRegExp m_keywordPattern;
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -60,10 +59,8 @@ MercurialSubmitHighlighter::MercurialSubmitHighlighter(QTextEdit *parent) :
|
|||||||
TextEditor::SyntaxHighlighter(parent),
|
TextEditor::SyntaxHighlighter(parent),
|
||||||
m_keywordPattern(QLatin1String("^\\w+:"))
|
m_keywordPattern(QLatin1String("^\\w+:"))
|
||||||
{
|
{
|
||||||
static const QVector<TextEditor::TextStyle> categories({TextEditor::C_COMMENT});
|
|
||||||
|
|
||||||
setTextFormatCategories(categories);
|
|
||||||
QTC_CHECK(m_keywordPattern.isValid());
|
QTC_CHECK(m_keywordPattern.isValid());
|
||||||
|
setDefaultTextFormatCategories();
|
||||||
}
|
}
|
||||||
|
|
||||||
void MercurialSubmitHighlighter::highlightBlock(const QString &text)
|
void MercurialSubmitHighlighter::highlightBlock(const QString &text)
|
||||||
@@ -71,7 +68,7 @@ void MercurialSubmitHighlighter::highlightBlock(const QString &text)
|
|||||||
// figure out current state
|
// figure out current state
|
||||||
State state = static_cast<State>(previousBlockState());
|
State state = static_cast<State>(previousBlockState());
|
||||||
if (text.startsWith(QLatin1String("HG:"))) {
|
if (text.startsWith(QLatin1String("HG:"))) {
|
||||||
setFormat(0, text.size(), formatForCategory(Format_Comment));
|
setFormat(0, text.size(), formatForCategory(TextEditor::C_COMMENT));
|
||||||
setCurrentBlockState(state);
|
setCurrentBlockState(state);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -35,7 +35,7 @@ namespace Nim {
|
|||||||
|
|
||||||
NimHighlighter::NimHighlighter()
|
NimHighlighter::NimHighlighter()
|
||||||
{
|
{
|
||||||
initTextFormats();
|
setDefaultTextFormatCategories();
|
||||||
}
|
}
|
||||||
|
|
||||||
void NimHighlighter::highlightBlock(const QString &text)
|
void NimHighlighter::highlightBlock(const QString &text)
|
||||||
@@ -43,56 +43,36 @@ void NimHighlighter::highlightBlock(const QString &text)
|
|||||||
setCurrentBlockState(highlightLine(text, previousBlockState()));
|
setCurrentBlockState(highlightLine(text, previousBlockState()));
|
||||||
}
|
}
|
||||||
|
|
||||||
void NimHighlighter::initTextFormats()
|
TextEditor::TextStyle NimHighlighter::styleForToken(const NimLexer::Token &token,
|
||||||
{
|
|
||||||
static QMap<Category, TextEditor::TextStyle> categoryStyle = {
|
|
||||||
{TextCategory, TextEditor::C_TEXT},
|
|
||||||
{KeywordCategory, TextEditor::C_KEYWORD},
|
|
||||||
{CommentCategory, TextEditor::C_COMMENT},
|
|
||||||
{DocumentationCategory, TextEditor::C_DOXYGEN_COMMENT},
|
|
||||||
{TypeCategory, TextEditor::C_TYPE},
|
|
||||||
{StringCategory, TextEditor::C_STRING},
|
|
||||||
{NumberCategory, TextEditor::C_NUMBER},
|
|
||||||
{OperatorCategory, TextEditor::C_OPERATOR},
|
|
||||||
{FunctionCategory, TextEditor::C_FUNCTION},
|
|
||||||
};
|
|
||||||
|
|
||||||
QVector<TextEditor::TextStyle> formats;
|
|
||||||
for (const auto &category : categoryStyle.keys())
|
|
||||||
formats << categoryStyle[category];
|
|
||||||
setTextFormatCategories(formats);
|
|
||||||
}
|
|
||||||
|
|
||||||
NimHighlighter::Category NimHighlighter::categoryForToken(const NimLexer::Token &token,
|
|
||||||
const QString &tokenValue)
|
const QString &tokenValue)
|
||||||
{
|
{
|
||||||
switch (token.type) {
|
switch (token.type) {
|
||||||
case NimLexer::TokenType::Keyword:
|
case NimLexer::TokenType::Keyword:
|
||||||
return KeywordCategory;
|
return TextEditor::C_KEYWORD;
|
||||||
case NimLexer::TokenType::Identifier:
|
case NimLexer::TokenType::Identifier:
|
||||||
return categoryForIdentifier(token, tokenValue);
|
return styleForIdentifier(token, tokenValue);
|
||||||
case NimLexer::TokenType::Comment:
|
case NimLexer::TokenType::Comment:
|
||||||
return CommentCategory;
|
return TextEditor::C_COMMENT;
|
||||||
case NimLexer::TokenType::Documentation:
|
case NimLexer::TokenType::Documentation:
|
||||||
return DocumentationCategory;
|
return TextEditor::C_DOXYGEN_COMMENT;
|
||||||
case NimLexer::TokenType::StringLiteral:
|
case NimLexer::TokenType::StringLiteral:
|
||||||
return StringCategory;
|
return TextEditor::C_STRING;
|
||||||
case NimLexer::TokenType::MultiLineStringLiteral:
|
case NimLexer::TokenType::MultiLineStringLiteral:
|
||||||
return StringCategory;
|
return TextEditor::C_STRING;
|
||||||
case NimLexer::TokenType::Operator:
|
case NimLexer::TokenType::Operator:
|
||||||
return OperatorCategory;
|
return TextEditor::C_OPERATOR;
|
||||||
case NimLexer::TokenType::Number:
|
case NimLexer::TokenType::Number:
|
||||||
return NumberCategory;
|
return TextEditor::C_NUMBER;
|
||||||
default:
|
default:
|
||||||
return TextCategory;
|
return TextEditor::C_TEXT;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
NimHighlighter::Category NimHighlighter::categoryForIdentifier(const NimLexer::Token &token,
|
TextEditor::TextStyle NimHighlighter::styleForIdentifier(const NimLexer::Token &token,
|
||||||
const QString &tokenValue)
|
const QString &tokenValue)
|
||||||
{
|
{
|
||||||
Q_UNUSED(token)
|
Q_UNUSED(token)
|
||||||
QTC_ASSERT(token.type == NimLexer::TokenType::Identifier, return TextCategory);
|
QTC_ASSERT(token.type == NimLexer::TokenType::Identifier, return TextEditor::C_TEXT);
|
||||||
|
|
||||||
static QSet<QString> nimBuiltInValues {
|
static QSet<QString> nimBuiltInValues {
|
||||||
"true", "false"
|
"true", "false"
|
||||||
@@ -111,12 +91,12 @@ NimHighlighter::Category NimHighlighter::categoryForIdentifier(const NimLexer::T
|
|||||||
};
|
};
|
||||||
|
|
||||||
if (nimBuiltInFunctions.contains(tokenValue))
|
if (nimBuiltInFunctions.contains(tokenValue))
|
||||||
return TypeCategory;
|
return TextEditor::C_TYPE;
|
||||||
if (nimBuiltInValues.contains(tokenValue))
|
if (nimBuiltInValues.contains(tokenValue))
|
||||||
return KeywordCategory;
|
return TextEditor::C_KEYWORD;
|
||||||
if (nimBuiltInTypes.contains(tokenValue))
|
if (nimBuiltInTypes.contains(tokenValue))
|
||||||
return TypeCategory;
|
return TextEditor::C_TYPE;
|
||||||
return TextCategory;
|
return TextEditor::C_TEXT;
|
||||||
}
|
}
|
||||||
|
|
||||||
int NimHighlighter::highlightLine(const QString &text, int initialState)
|
int NimHighlighter::highlightLine(const QString &text, int initialState)
|
||||||
@@ -127,8 +107,8 @@ int NimHighlighter::highlightLine(const QString &text, int initialState)
|
|||||||
|
|
||||||
NimLexer::Token tk;
|
NimLexer::Token tk;
|
||||||
while ((tk = lexer.next()).type != NimLexer::TokenType::EndOfText) {
|
while ((tk = lexer.next()).type != NimLexer::TokenType::EndOfText) {
|
||||||
int category = categoryForToken(tk, text.mid(tk.begin, tk.length));
|
TextEditor::TextStyle style = styleForToken(tk, text.mid(tk.begin, tk.length));
|
||||||
setFormat(tk.begin, tk.length, formatForCategory(category));
|
setFormat(tk.begin, tk.length, formatForCategory(style));
|
||||||
}
|
}
|
||||||
|
|
||||||
return lexer.state();
|
return lexer.state();
|
||||||
|
|||||||
@@ -35,18 +35,6 @@ class NimHighlighter : public TextEditor::SyntaxHighlighter
|
|||||||
{
|
{
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
|
|
||||||
enum Category {
|
|
||||||
TextCategory = 0,
|
|
||||||
KeywordCategory,
|
|
||||||
CommentCategory,
|
|
||||||
DocumentationCategory,
|
|
||||||
TypeCategory,
|
|
||||||
StringCategory,
|
|
||||||
NumberCategory,
|
|
||||||
OperatorCategory,
|
|
||||||
FunctionCategory
|
|
||||||
};
|
|
||||||
|
|
||||||
public:
|
public:
|
||||||
NimHighlighter();
|
NimHighlighter();
|
||||||
|
|
||||||
@@ -54,10 +42,8 @@ protected:
|
|||||||
void highlightBlock(const QString &text) override;
|
void highlightBlock(const QString &text) override;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
void initTextFormats();
|
TextEditor::TextStyle styleForToken(const NimLexer::Token &token, const QString &tokenValue);
|
||||||
|
TextEditor::TextStyle styleForIdentifier(const NimLexer::Token &token, const QString &tokenValue);
|
||||||
Category categoryForToken(const NimLexer::Token &token, const QString &tokenValue);
|
|
||||||
Category categoryForIdentifier(const NimLexer::Token &token, const QString &tokenValue);
|
|
||||||
|
|
||||||
int highlightLine(const QString &text, int initialState);
|
int highlightLine(const QString &text, int initialState);
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -38,6 +38,7 @@
|
|||||||
|
|
||||||
#include <texteditor/textdocument.h>
|
#include <texteditor/textdocument.h>
|
||||||
#include <texteditor/texteditorconstants.h>
|
#include <texteditor/texteditorconstants.h>
|
||||||
|
#include <utils/qtcassert.h>
|
||||||
|
|
||||||
namespace PythonEditor {
|
namespace PythonEditor {
|
||||||
namespace Internal {
|
namespace Internal {
|
||||||
@@ -60,23 +61,34 @@ namespace Internal {
|
|||||||
* @endcode
|
* @endcode
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
static TextEditor::TextStyle styleForFormat(int format)
|
||||||
|
{
|
||||||
|
using namespace TextEditor;
|
||||||
|
const auto f = Format(format);
|
||||||
|
switch (f) {
|
||||||
|
case Format_Number: return C_NUMBER;
|
||||||
|
case Format_String: return C_STRING;
|
||||||
|
case Format_Keyword: return C_KEYWORD;
|
||||||
|
case Format_Type: return C_TYPE;
|
||||||
|
case Format_ClassField: return C_FIELD;
|
||||||
|
case Format_MagicAttr: return C_JS_SCOPE_VAR;
|
||||||
|
case Format_Operator: return C_OPERATOR;
|
||||||
|
case Format_Comment: return C_COMMENT;
|
||||||
|
case Format_Doxygen: return C_DOXYGEN_COMMENT;
|
||||||
|
case Format_Identifier: return C_TEXT;
|
||||||
|
case Format_Whitespace: return C_VISUAL_WHITESPACE;
|
||||||
|
case Format_ImportedModule: return C_STRING;
|
||||||
|
case Format_FormatsAmount:
|
||||||
|
QTC_CHECK(false); // should never get here
|
||||||
|
return C_TEXT;
|
||||||
|
}
|
||||||
|
QTC_CHECK(false); // should never get here
|
||||||
|
return C_TEXT;
|
||||||
|
}
|
||||||
|
|
||||||
PythonHighlighter::PythonHighlighter()
|
PythonHighlighter::PythonHighlighter()
|
||||||
{
|
{
|
||||||
static const QVector<TextEditor::TextStyle> categories = {
|
setTextFormatCategories(Format_FormatsAmount, styleForFormat);
|
||||||
TextEditor::C_NUMBER,
|
|
||||||
TextEditor::C_STRING,
|
|
||||||
TextEditor::C_KEYWORD,
|
|
||||||
TextEditor::C_TYPE,
|
|
||||||
TextEditor::C_FIELD,
|
|
||||||
TextEditor::C_JS_SCOPE_VAR,
|
|
||||||
TextEditor::C_OPERATOR,
|
|
||||||
TextEditor::C_COMMENT,
|
|
||||||
TextEditor::C_DOXYGEN_COMMENT,
|
|
||||||
TextEditor::C_TEXT,
|
|
||||||
TextEditor::C_VISUAL_WHITESPACE,
|
|
||||||
TextEditor::C_STRING
|
|
||||||
};
|
|
||||||
setTextFormatCategories(categories);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -27,6 +27,7 @@
|
|||||||
#include "profilecompletionassist.h"
|
#include "profilecompletionassist.h"
|
||||||
|
|
||||||
#include <extensionsystem/pluginmanager.h>
|
#include <extensionsystem/pluginmanager.h>
|
||||||
|
#include <utils/qtcassert.h>
|
||||||
|
|
||||||
#include <QTextDocument>
|
#include <QTextDocument>
|
||||||
|
|
||||||
@@ -35,11 +36,26 @@ using namespace TextEditor;
|
|||||||
namespace QmakeProjectManager {
|
namespace QmakeProjectManager {
|
||||||
namespace Internal {
|
namespace Internal {
|
||||||
|
|
||||||
|
static TextStyle styleForFormat(int format)
|
||||||
|
{
|
||||||
|
const auto f = ProFileHighlighter::ProfileFormats(format);
|
||||||
|
switch (f) {
|
||||||
|
case ProFileHighlighter::ProfileVariableFormat: return C_TYPE;
|
||||||
|
case ProFileHighlighter::ProfileFunctionFormat: return C_KEYWORD;
|
||||||
|
case ProFileHighlighter::ProfileCommentFormat: return C_COMMENT;
|
||||||
|
case ProFileHighlighter::ProfileVisualWhitespaceFormat: return C_VISUAL_WHITESPACE;
|
||||||
|
case ProFileHighlighter::NumProfileFormats:
|
||||||
|
QTC_CHECK(false); // should never get here
|
||||||
|
return C_TEXT;
|
||||||
|
}
|
||||||
|
QTC_CHECK(false); // should never get here
|
||||||
|
return C_TEXT;
|
||||||
|
}
|
||||||
|
|
||||||
ProFileHighlighter::ProFileHighlighter(const Keywords &keywords)
|
ProFileHighlighter::ProFileHighlighter(const Keywords &keywords)
|
||||||
: m_keywords(keywords)
|
: m_keywords(keywords)
|
||||||
{
|
{
|
||||||
static const QVector<TextStyle> categories({C_TYPE, C_KEYWORD, C_COMMENT, C_VISUAL_WHITESPACE});
|
setTextFormatCategories(NumProfileFormats, styleForFormat);
|
||||||
setTextFormatCategories(categories);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void ProFileHighlighter::highlightBlock(const QString &text)
|
void ProFileHighlighter::highlightBlock(const QString &text)
|
||||||
|
|||||||
@@ -42,10 +42,7 @@ QmlJSHighlighter::QmlJSHighlighter(QTextDocument *parent)
|
|||||||
m_inMultilineComment(false)
|
m_inMultilineComment(false)
|
||||||
{
|
{
|
||||||
m_currentBlockParentheses.reserve(20);
|
m_currentBlockParentheses.reserve(20);
|
||||||
static const QVector<TextStyle> categories({
|
setDefaultTextFormatCategories();
|
||||||
C_NUMBER, C_STRING, C_TYPE, C_KEYWORD, C_FIELD, C_COMMENT, C_VISUAL_WHITESPACE
|
|
||||||
});
|
|
||||||
setTextFormatCategories(categories);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
QmlJSHighlighter::~QmlJSHighlighter()
|
QmlJSHighlighter::~QmlJSHighlighter()
|
||||||
@@ -72,11 +69,11 @@ void QmlJSHighlighter::highlightBlock(const QString &text)
|
|||||||
|
|
||||||
switch (token.kind) {
|
switch (token.kind) {
|
||||||
case Token::Keyword:
|
case Token::Keyword:
|
||||||
setFormat(token.offset, token.length, formatForCategory(KeywordFormat));
|
setFormat(token.offset, token.length, formatForCategory(C_KEYWORD));
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case Token::String:
|
case Token::String:
|
||||||
setFormat(token.offset, token.length, formatForCategory(StringFormat));
|
setFormat(token.offset, token.length, formatForCategory(C_STRING));
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case Token::Comment:
|
case Token::Comment:
|
||||||
@@ -89,11 +86,11 @@ void QmlJSHighlighter::highlightBlock(const QString &text)
|
|||||||
onOpeningParenthesis(QLatin1Char('+'), token.offset, index == 0);
|
onOpeningParenthesis(QLatin1Char('+'), token.offset, index == 0);
|
||||||
m_inMultilineComment = true;
|
m_inMultilineComment = true;
|
||||||
}
|
}
|
||||||
setFormat(token.offset, token.length, formatForCategory(CommentFormat));
|
setFormat(token.offset, token.length, formatForCategory(C_COMMENT));
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case Token::RegExp:
|
case Token::RegExp:
|
||||||
setFormat(token.offset, token.length, formatForCategory(StringFormat));
|
setFormat(token.offset, token.length, formatForCategory(C_STRING));
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case Token::LeftParenthesis:
|
case Token::LeftParenthesis:
|
||||||
@@ -130,7 +127,7 @@ void QmlJSHighlighter::highlightBlock(const QString &text)
|
|||||||
// check the previous token
|
// check the previous token
|
||||||
if (index == 0 || tokens.at(index - 1).isNot(Token::Dot)) {
|
if (index == 0 || tokens.at(index - 1).isNot(Token::Dot)) {
|
||||||
if (index + 1 == tokens.size() || tokens.at(index + 1).isNot(Token::Colon)) {
|
if (index + 1 == tokens.size() || tokens.at(index + 1).isNot(Token::Colon)) {
|
||||||
setFormat(token.offset, token.length, formatForCategory(KeywordFormat));
|
setFormat(token.offset, token.length, formatForCategory(C_KEYWORD));
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -138,7 +135,7 @@ void QmlJSHighlighter::highlightBlock(const QString &text)
|
|||||||
const Token &previousToken = tokens.at(index - 1);
|
const Token &previousToken = tokens.at(index - 1);
|
||||||
if (previousToken.is(Token::Identifier) && text.at(previousToken.offset) == QLatin1Char('p')
|
if (previousToken.is(Token::Identifier) && text.at(previousToken.offset) == QLatin1Char('p')
|
||||||
&& text.midRef(previousToken.offset, previousToken.length) == QLatin1String("property")) {
|
&& text.midRef(previousToken.offset, previousToken.length) == QLatin1String("property")) {
|
||||||
setFormat(token.offset, token.length, formatForCategory(KeywordFormat));
|
setFormat(token.offset, token.length, formatForCategory(C_KEYWORD));
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -157,7 +154,7 @@ void QmlJSHighlighter::highlightBlock(const QString &text)
|
|||||||
int previousTokenEnd = 0;
|
int previousTokenEnd = 0;
|
||||||
for (int index = 0; index < tokens.size(); ++index) {
|
for (int index = 0; index < tokens.size(); ++index) {
|
||||||
const Token &token = tokens.at(index);
|
const Token &token = tokens.at(index);
|
||||||
setFormat(previousTokenEnd, token.begin() - previousTokenEnd, formatForCategory(VisualWhitespace));
|
setFormat(previousTokenEnd, token.begin() - previousTokenEnd, formatForCategory(C_VISUAL_WHITESPACE));
|
||||||
|
|
||||||
switch (token.kind) {
|
switch (token.kind) {
|
||||||
case Token::Comment:
|
case Token::Comment:
|
||||||
@@ -171,7 +168,7 @@ void QmlJSHighlighter::highlightBlock(const QString &text)
|
|||||||
do {
|
do {
|
||||||
++i;
|
++i;
|
||||||
} while (i < e && text.at(i).isSpace());
|
} while (i < e && text.at(i).isSpace());
|
||||||
setFormat(start, i - start, formatForCategory(VisualWhitespace));
|
setFormat(start, i - start, formatForCategory(C_VISUAL_WHITESPACE));
|
||||||
} else {
|
} else {
|
||||||
++i;
|
++i;
|
||||||
}
|
}
|
||||||
@@ -185,7 +182,7 @@ void QmlJSHighlighter::highlightBlock(const QString &text)
|
|||||||
previousTokenEnd = token.end();
|
previousTokenEnd = token.end();
|
||||||
}
|
}
|
||||||
|
|
||||||
setFormat(previousTokenEnd, text.length() - previousTokenEnd, formatForCategory(VisualWhitespace));
|
setFormat(previousTokenEnd, text.length() - previousTokenEnd, formatForCategory(C_VISUAL_WHITESPACE));
|
||||||
|
|
||||||
setCurrentBlockState(m_scanner.state());
|
setCurrentBlockState(m_scanner.state());
|
||||||
onBlockEnd(m_scanner.state());
|
onBlockEnd(m_scanner.state());
|
||||||
|
|||||||
@@ -42,17 +42,6 @@ public:
|
|||||||
QmlJSHighlighter(QTextDocument *parent = 0);
|
QmlJSHighlighter(QTextDocument *parent = 0);
|
||||||
virtual ~QmlJSHighlighter();
|
virtual ~QmlJSHighlighter();
|
||||||
|
|
||||||
enum {
|
|
||||||
NumberFormat,
|
|
||||||
StringFormat,
|
|
||||||
TypeFormat,
|
|
||||||
KeywordFormat,
|
|
||||||
FieldFormat,
|
|
||||||
CommentFormat,
|
|
||||||
VisualWhitespace,
|
|
||||||
NumFormats
|
|
||||||
};
|
|
||||||
|
|
||||||
bool isQmlEnabled() const;
|
bool isQmlEnabled() const;
|
||||||
void setQmlEnabled(bool duiEnabled);
|
void setQmlEnabled(bool duiEnabled);
|
||||||
|
|
||||||
|
|||||||
@@ -34,6 +34,7 @@
|
|||||||
#include "tabsettings.h"
|
#include "tabsettings.h"
|
||||||
|
|
||||||
#include <coreplugin/messagemanager.h>
|
#include <coreplugin/messagemanager.h>
|
||||||
|
#include <utils/qtcassert.h>
|
||||||
|
|
||||||
#include <QCoreApplication>
|
#include <QCoreApplication>
|
||||||
|
|
||||||
@@ -77,6 +78,46 @@ HighlighterCodeFormatterData *formatterData(const QTextBlock &block)
|
|||||||
return data;
|
return data;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static TextStyle styleForFormat(int format)
|
||||||
|
{
|
||||||
|
const auto f = Highlighter::TextFormatId(format);
|
||||||
|
switch (f) {
|
||||||
|
case Highlighter::Normal: return C_TEXT;
|
||||||
|
case Highlighter::VisualWhitespace: return C_VISUAL_WHITESPACE;
|
||||||
|
case Highlighter::Keyword: return C_KEYWORD;
|
||||||
|
case Highlighter::DataType: return C_TYPE;
|
||||||
|
case Highlighter::Comment: return C_COMMENT;
|
||||||
|
case Highlighter::Decimal: return C_NUMBER;
|
||||||
|
case Highlighter::BaseN: return C_NUMBER;
|
||||||
|
case Highlighter::Float: return C_NUMBER;
|
||||||
|
case Highlighter::Char: return C_STRING;
|
||||||
|
case Highlighter::SpecialChar: return C_STRING;
|
||||||
|
case Highlighter::String: return C_STRING;
|
||||||
|
case Highlighter::Alert: return C_WARNING;
|
||||||
|
case Highlighter::Information: return C_TEXT;
|
||||||
|
case Highlighter::Warning: return C_WARNING;
|
||||||
|
case Highlighter::Error: return C_ERROR;
|
||||||
|
case Highlighter::Function: return C_FUNCTION;
|
||||||
|
case Highlighter::RegionMarker: return C_TEXT;
|
||||||
|
case Highlighter::BuiltIn: return C_PREPROCESSOR;
|
||||||
|
case Highlighter::Extension: return C_PRIMITIVE_TYPE;
|
||||||
|
case Highlighter::Operator: return C_OPERATOR;
|
||||||
|
case Highlighter::Variable: return C_LOCAL;
|
||||||
|
case Highlighter::Attribute: return C_LABEL;
|
||||||
|
case Highlighter::Annotation: return C_TEXT;
|
||||||
|
case Highlighter::CommentVar: return C_COMMENT;
|
||||||
|
case Highlighter::Import: return C_PREPROCESSOR;
|
||||||
|
case Highlighter::Others: return C_TEXT;
|
||||||
|
case Highlighter::Identifier: return C_LOCAL;
|
||||||
|
case Highlighter::Documentation: return C_DOXYGEN_COMMENT;
|
||||||
|
case Highlighter::TextFormatIdCount:
|
||||||
|
QTC_CHECK(false); // should never get here
|
||||||
|
return C_TEXT;
|
||||||
|
}
|
||||||
|
QTC_CHECK(false); // should never get here
|
||||||
|
return C_TEXT;
|
||||||
|
}
|
||||||
|
|
||||||
Highlighter::Highlighter(QTextDocument *parent) :
|
Highlighter::Highlighter(QTextDocument *parent) :
|
||||||
SyntaxHighlighter(parent),
|
SyntaxHighlighter(parent),
|
||||||
m_regionDepth(0),
|
m_regionDepth(0),
|
||||||
@@ -86,38 +127,7 @@ Highlighter::Highlighter(QTextDocument *parent) :
|
|||||||
m_dynamicContextsCounter(0),
|
m_dynamicContextsCounter(0),
|
||||||
m_isBroken(false)
|
m_isBroken(false)
|
||||||
{
|
{
|
||||||
static const QVector<TextStyle> categories({
|
setTextFormatCategories(TextFormatIdCount, styleForFormat);
|
||||||
C_TEXT, // Normal
|
|
||||||
C_VISUAL_WHITESPACE, // VisualWhitespace
|
|
||||||
C_KEYWORD, // Keyword
|
|
||||||
C_TYPE, // DataType
|
|
||||||
C_COMMENT, // Comment
|
|
||||||
C_NUMBER, // Decimal
|
|
||||||
C_NUMBER, // BaseN
|
|
||||||
C_NUMBER, // Float
|
|
||||||
C_STRING, // Char
|
|
||||||
C_STRING, // SpecialChar
|
|
||||||
C_STRING, // String
|
|
||||||
C_WARNING, // Alert
|
|
||||||
C_TEXT, // Information
|
|
||||||
C_WARNING, // Warning
|
|
||||||
C_ERROR, // Error
|
|
||||||
C_FUNCTION, // Function
|
|
||||||
C_TEXT, // RegionMarker
|
|
||||||
C_PREPROCESSOR, // BuiltIn
|
|
||||||
C_PRIMITIVE_TYPE, // Extension
|
|
||||||
C_OPERATOR, // Operator
|
|
||||||
C_LOCAL, // Variable
|
|
||||||
C_LABEL, // Attribute
|
|
||||||
C_TEXT, // Annotation
|
|
||||||
C_COMMENT, // CommentVar
|
|
||||||
C_PREPROCESSOR, // Import
|
|
||||||
C_TEXT, // Others
|
|
||||||
C_LOCAL, // Identifier
|
|
||||||
C_DOXYGEN_COMMENT // Documentation
|
|
||||||
});
|
|
||||||
|
|
||||||
setTextFormatCategories(categories);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
Highlighter::~Highlighter()
|
Highlighter::~Highlighter()
|
||||||
|
|||||||
@@ -91,7 +91,8 @@ public:
|
|||||||
Import,
|
Import,
|
||||||
Others,
|
Others,
|
||||||
Identifier,
|
Identifier,
|
||||||
Documentation
|
Documentation,
|
||||||
|
TextFormatIdCount
|
||||||
};
|
};
|
||||||
|
|
||||||
void setTabSettings(const TabSettings &ts);
|
void setTabSettings(const TabSettings &ts);
|
||||||
|
|||||||
@@ -30,6 +30,7 @@
|
|||||||
#include "fontsettings.h"
|
#include "fontsettings.h"
|
||||||
|
|
||||||
#include <utils/algorithm.h>
|
#include <utils/algorithm.h>
|
||||||
|
#include <utils/asconst.h>
|
||||||
#include <utils/qtcassert.h>
|
#include <utils/qtcassert.h>
|
||||||
|
|
||||||
#include <QTextDocument>
|
#include <QTextDocument>
|
||||||
@@ -71,7 +72,7 @@ public:
|
|||||||
bool inReformatBlocks;
|
bool inReformatBlocks;
|
||||||
TextDocumentLayout::FoldValidator foldValidator;
|
TextDocumentLayout::FoldValidator foldValidator;
|
||||||
QVector<QTextCharFormat> formats;
|
QVector<QTextCharFormat> formats;
|
||||||
QVector<TextStyle> formatCategories;
|
QVector<std::pair<int,TextStyle>> formatCategories;
|
||||||
};
|
};
|
||||||
|
|
||||||
static bool adjustRange(QTextLayout::FormatRange &range, int from, int charsRemoved, int charsAdded) {
|
static bool adjustRange(QTextLayout::FormatRange &range, int from, int charsRemoved, int charsAdded) {
|
||||||
@@ -727,10 +728,49 @@ void SyntaxHighlighter::setFontSettings(const FontSettings &fontSettings)
|
|||||||
d->updateFormatsForCategories(fontSettings);
|
d->updateFormatsForCategories(fontSettings);
|
||||||
}
|
}
|
||||||
|
|
||||||
void SyntaxHighlighter::setTextFormatCategories(const QVector<TextStyle> &categories)
|
/*!
|
||||||
|
Creates text format categories for the text styles themselves, so the highlighter can
|
||||||
|
use \c{formatForCategory(C_COMMENT)} and similar, and avoid creating its own format enum.
|
||||||
|
\sa setTextFormatCategories()
|
||||||
|
*/
|
||||||
|
void SyntaxHighlighter::setDefaultTextFormatCategories()
|
||||||
|
{
|
||||||
|
// map all text styles to themselves
|
||||||
|
setTextFormatCategories(C_LAST_STYLE_SENTINEL, [](int i) { return TextStyle(i); });
|
||||||
|
}
|
||||||
|
|
||||||
|
/*!
|
||||||
|
Uses the \a formatMapping function to create a mapping from the custom formats (the ints)
|
||||||
|
to text styles. The \a formatMapping must handle all values from 0 to \a count.
|
||||||
|
|
||||||
|
\sa setDefaultTextFormatCategories()
|
||||||
|
\sa setTextFormatCategories()
|
||||||
|
*/
|
||||||
|
void SyntaxHighlighter::setTextFormatCategories(int count,
|
||||||
|
std::function<TextStyle(int)> formatMapping)
|
||||||
|
{
|
||||||
|
QVector<std::pair<int, TextStyle>> categories;
|
||||||
|
categories.reserve(count);
|
||||||
|
for (int i = 0; i < count; ++i)
|
||||||
|
categories.append({i, formatMapping(i)});
|
||||||
|
setTextFormatCategories(categories);
|
||||||
|
}
|
||||||
|
|
||||||
|
/*!
|
||||||
|
Creates a mapping between custom format enum values (the int values in the pairs) to
|
||||||
|
text styles. Afterwards \c{formatForCategory(MyCustomFormatEnumValue)} can be used to
|
||||||
|
efficiently retrieve the text style for a value.
|
||||||
|
|
||||||
|
Note that this creates a vector with a size of the maximum int value in \a categories.
|
||||||
|
|
||||||
|
\sa setDefaultTextFormatCategories()
|
||||||
|
*/
|
||||||
|
void SyntaxHighlighter::setTextFormatCategories(const QVector<std::pair<int, TextStyle>> &categories)
|
||||||
{
|
{
|
||||||
Q_D(SyntaxHighlighter);
|
Q_D(SyntaxHighlighter);
|
||||||
d->formatCategories = categories;
|
d->formatCategories = categories;
|
||||||
|
const int maxCategory = Utils::maxElementOr(categories, {-1, C_TEXT}).first;
|
||||||
|
d->formats = QVector<QTextCharFormat>(maxCategory + 1);
|
||||||
d->updateFormatsForCategories(TextEditorSettings::fontSettings());
|
d->updateFormatsForCategories(TextEditorSettings::fontSettings());
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -744,7 +784,8 @@ QTextCharFormat SyntaxHighlighter::formatForCategory(int category) const
|
|||||||
|
|
||||||
void SyntaxHighlighterPrivate::updateFormatsForCategories(const FontSettings &fontSettings)
|
void SyntaxHighlighterPrivate::updateFormatsForCategories(const FontSettings &fontSettings)
|
||||||
{
|
{
|
||||||
formats = fontSettings.toTextCharFormats(formatCategories);
|
for (const auto &pair : Utils::asConst(formatCategories))
|
||||||
|
formats[pair.first] = fontSettings.toTextCharFormat(pair.second);
|
||||||
}
|
}
|
||||||
|
|
||||||
} // namespace TextEditor
|
} // namespace TextEditor
|
||||||
|
|||||||
@@ -26,10 +26,14 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include "texteditor_global.h"
|
#include "texteditor_global.h"
|
||||||
|
|
||||||
#include <texteditor/texteditorconstants.h>
|
#include <texteditor/texteditorconstants.h>
|
||||||
|
|
||||||
#include <QObject>
|
#include <QObject>
|
||||||
#include <QTextLayout>
|
#include <QTextLayout>
|
||||||
|
|
||||||
|
#include <functional>
|
||||||
|
|
||||||
QT_BEGIN_NAMESPACE
|
QT_BEGIN_NAMESPACE
|
||||||
class QTextDocument;
|
class QTextDocument;
|
||||||
class QSyntaxHighlighterPrivate;
|
class QSyntaxHighlighterPrivate;
|
||||||
@@ -70,7 +74,8 @@ public slots:
|
|||||||
void rehighlightBlock(const QTextBlock &block);
|
void rehighlightBlock(const QTextBlock &block);
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
void setTextFormatCategories(const QVector<TextEditor::TextStyle> &categories);
|
void setDefaultTextFormatCategories();
|
||||||
|
void setTextFormatCategories(int count, std::function<TextStyle(int)> formatMapping);
|
||||||
QTextCharFormat formatForCategory(int categoryIndex) const;
|
QTextCharFormat formatForCategory(int categoryIndex) const;
|
||||||
virtual void highlightBlock(const QString &text) = 0;
|
virtual void highlightBlock(const QString &text) = 0;
|
||||||
|
|
||||||
@@ -91,6 +96,7 @@ protected:
|
|||||||
QTextBlock currentBlock() const;
|
QTextBlock currentBlock() const;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
void setTextFormatCategories(const QVector<std::pair<int, TextStyle>> &categories);
|
||||||
void reformatBlocks(int from, int charsRemoved, int charsAdded);
|
void reformatBlocks(int from, int charsRemoved, int charsAdded);
|
||||||
void delayedRehighlight();
|
void delayedRehighlight();
|
||||||
|
|
||||||
|
|||||||
@@ -52,10 +52,6 @@ namespace VcsBase {
|
|||||||
class BaseAnnotationHighlighterPrivate
|
class BaseAnnotationHighlighterPrivate
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
enum Formats {
|
|
||||||
BackgroundFormat // C_TEXT
|
|
||||||
};
|
|
||||||
|
|
||||||
BaseAnnotationHighlighterPrivate(BaseAnnotationHighlighter *q_) : q(q_) { }
|
BaseAnnotationHighlighterPrivate(BaseAnnotationHighlighter *q_) : q(q_) { }
|
||||||
|
|
||||||
void updateOtherFormats();
|
void updateOtherFormats();
|
||||||
@@ -67,7 +63,8 @@ public:
|
|||||||
|
|
||||||
void BaseAnnotationHighlighterPrivate::updateOtherFormats()
|
void BaseAnnotationHighlighterPrivate::updateOtherFormats()
|
||||||
{
|
{
|
||||||
m_background = q->formatForCategory(BackgroundFormat).brushProperty(QTextFormat::BackgroundBrush).color();
|
m_background = q->formatForCategory(TextEditor::C_TEXT)
|
||||||
|
.brushProperty(QTextFormat::BackgroundBrush).color();
|
||||||
q->setChangeNumbers(m_changeNumberMap.keys().toSet());
|
q->setChangeNumbers(m_changeNumberMap.keys().toSet());
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -76,9 +73,7 @@ BaseAnnotationHighlighter::BaseAnnotationHighlighter(const ChangeNumbers &change
|
|||||||
TextEditor::SyntaxHighlighter(document),
|
TextEditor::SyntaxHighlighter(document),
|
||||||
d(new BaseAnnotationHighlighterPrivate(this))
|
d(new BaseAnnotationHighlighterPrivate(this))
|
||||||
{
|
{
|
||||||
static const QVector<TextEditor::TextStyle> categories({TextEditor::C_TEXT});
|
setDefaultTextFormatCategories();
|
||||||
|
|
||||||
setTextFormatCategories(categories);
|
|
||||||
d->updateOtherFormats();
|
d->updateOtherFormats();
|
||||||
|
|
||||||
setChangeNumbers(changeNumbers);
|
setChangeNumbers(changeNumbers);
|
||||||
|
|||||||
@@ -67,16 +67,6 @@ static const int LOCATION_LEVEL = 2;
|
|||||||
namespace VcsBase {
|
namespace VcsBase {
|
||||||
namespace Internal {
|
namespace Internal {
|
||||||
|
|
||||||
// Formats used by DiffAndLogHighlighter
|
|
||||||
enum DiffFormats {
|
|
||||||
DiffTextFormat,
|
|
||||||
DiffInFormat,
|
|
||||||
DiffOutFormat,
|
|
||||||
DiffFileFormat,
|
|
||||||
DiffLocationFormat,
|
|
||||||
ChangeTextFormat
|
|
||||||
};
|
|
||||||
|
|
||||||
enum FoldingState {
|
enum FoldingState {
|
||||||
StartOfFile,
|
StartOfFile,
|
||||||
Header,
|
Header,
|
||||||
@@ -111,7 +101,7 @@ public:
|
|||||||
QTC_CHECK(filePattern.isValid());
|
QTC_CHECK(filePattern.isValid());
|
||||||
}
|
}
|
||||||
|
|
||||||
Internal::DiffFormats analyzeLine(const QString &block) const;
|
TextEditor::TextStyle analyzeLine(const QString &block) const;
|
||||||
void updateOtherFormats();
|
void updateOtherFormats();
|
||||||
|
|
||||||
DiffAndLogHighlighter *const q;
|
DiffAndLogHighlighter *const q;
|
||||||
@@ -126,27 +116,27 @@ public:
|
|||||||
Internal::FoldingState m_foldingState;
|
Internal::FoldingState m_foldingState;
|
||||||
};
|
};
|
||||||
|
|
||||||
Internal::DiffFormats DiffAndLogHighlighterPrivate::analyzeLine(const QString &text) const
|
TextEditor::TextStyle DiffAndLogHighlighterPrivate::analyzeLine(const QString &text) const
|
||||||
{
|
{
|
||||||
// Do not match on git "--- a/" as a deleted line, check
|
// Do not match on git "--- a/" as a deleted line, check
|
||||||
// file first
|
// file first
|
||||||
if (m_filePattern.indexIn(text) == 0)
|
if (m_filePattern.indexIn(text) == 0)
|
||||||
return Internal::DiffFileFormat;
|
return TextEditor::C_DIFF_FILE;
|
||||||
if (m_changePattern.indexIn(text) == 0)
|
if (m_changePattern.indexIn(text) == 0)
|
||||||
return Internal::ChangeTextFormat;
|
return TextEditor::C_LOG_CHANGE_LINE;
|
||||||
if (text.startsWith(m_diffInIndicator))
|
if (text.startsWith(m_diffInIndicator))
|
||||||
return Internal::DiffInFormat;
|
return TextEditor::C_ADDED_LINE;
|
||||||
if (text.startsWith(m_diffOutIndicator))
|
if (text.startsWith(m_diffOutIndicator))
|
||||||
return Internal::DiffOutFormat;
|
return TextEditor::C_REMOVED_LINE;
|
||||||
if (text.startsWith(m_locationIndicator))
|
if (text.startsWith(m_locationIndicator))
|
||||||
return Internal::DiffLocationFormat;
|
return TextEditor::C_DIFF_LOCATION;
|
||||||
return Internal::DiffTextFormat;
|
return TextEditor::C_TEXT;
|
||||||
}
|
}
|
||||||
|
|
||||||
void DiffAndLogHighlighterPrivate::updateOtherFormats()
|
void DiffAndLogHighlighterPrivate::updateOtherFormats()
|
||||||
{
|
{
|
||||||
m_addedTrailingWhiteSpaceFormat =
|
m_addedTrailingWhiteSpaceFormat =
|
||||||
invertedColorFormat(q->formatForCategory(Internal::DiffInFormat));
|
invertedColorFormat(q->formatForCategory(TextEditor::C_ADDED_LINE));
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -155,15 +145,7 @@ DiffAndLogHighlighter::DiffAndLogHighlighter(const QRegExp &filePattern, const Q
|
|||||||
TextEditor::SyntaxHighlighter(static_cast<QTextDocument *>(0)),
|
TextEditor::SyntaxHighlighter(static_cast<QTextDocument *>(0)),
|
||||||
d(new DiffAndLogHighlighterPrivate(this, filePattern, changePattern))
|
d(new DiffAndLogHighlighterPrivate(this, filePattern, changePattern))
|
||||||
{
|
{
|
||||||
static const QVector<TextEditor::TextStyle> categories({
|
setDefaultTextFormatCategories();
|
||||||
TextEditor::C_TEXT,
|
|
||||||
TextEditor::C_ADDED_LINE,
|
|
||||||
TextEditor::C_REMOVED_LINE,
|
|
||||||
TextEditor::C_DIFF_FILE,
|
|
||||||
TextEditor::C_DIFF_LOCATION,
|
|
||||||
TextEditor::C_LOG_CHANGE_LINE
|
|
||||||
});
|
|
||||||
setTextFormatCategories(categories);
|
|
||||||
d->updateOtherFormats();
|
d->updateOtherFormats();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -193,21 +175,16 @@ void DiffAndLogHighlighter::highlightBlock(const QString &text)
|
|||||||
return;
|
return;
|
||||||
|
|
||||||
const int length = text.length();
|
const int length = text.length();
|
||||||
const Internal::DiffFormats format = d->analyzeLine(text);
|
const TextEditor::TextStyle format = d->analyzeLine(text);
|
||||||
switch (format) {
|
|
||||||
case Internal::DiffTextFormat:
|
if (format == TextEditor::C_ADDED_LINE) {
|
||||||
break;
|
|
||||||
case Internal::DiffInFormat: {
|
|
||||||
// Mark trailing whitespace.
|
// Mark trailing whitespace.
|
||||||
const int trimmedLen = trimmedLength(text);
|
const int trimmedLen = trimmedLength(text);
|
||||||
setFormat(0, trimmedLen, formatForCategory(format));
|
setFormat(0, trimmedLen, formatForCategory(format));
|
||||||
if (trimmedLen != length)
|
if (trimmedLen != length)
|
||||||
setFormat(trimmedLen, length - trimmedLen, d->m_addedTrailingWhiteSpaceFormat);
|
setFormat(trimmedLen, length - trimmedLen, d->m_addedTrailingWhiteSpaceFormat);
|
||||||
}
|
} else if (format != TextEditor::C_TEXT) {
|
||||||
break;
|
|
||||||
default:
|
|
||||||
setFormat(0, length, formatForCategory(format));
|
setFormat(0, length, formatForCategory(format));
|
||||||
break;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// codefolding:
|
// codefolding:
|
||||||
@@ -220,47 +197,35 @@ void DiffAndLogHighlighter::highlightBlock(const QString &text)
|
|||||||
switch (d->m_foldingState) {
|
switch (d->m_foldingState) {
|
||||||
case Internal::StartOfFile:
|
case Internal::StartOfFile:
|
||||||
case Internal::Header:
|
case Internal::Header:
|
||||||
switch (format) {
|
if (format == TextEditor::C_DIFF_FILE) {
|
||||||
case Internal::DiffFileFormat:
|
|
||||||
d->m_foldingState = Internal::File;
|
d->m_foldingState = Internal::File;
|
||||||
TextEditor::TextDocumentLayout::setFoldingIndent(currentBlock(), BASE_LEVEL);
|
TextEditor::TextDocumentLayout::setFoldingIndent(currentBlock(), BASE_LEVEL);
|
||||||
break;
|
} else if (format == TextEditor::C_DIFF_LOCATION) {
|
||||||
case Internal::DiffLocationFormat:
|
|
||||||
d->m_foldingState = Internal::Location;
|
d->m_foldingState = Internal::Location;
|
||||||
TextEditor::TextDocumentLayout::setFoldingIndent(currentBlock(), FILE_LEVEL);
|
TextEditor::TextDocumentLayout::setFoldingIndent(currentBlock(), FILE_LEVEL);
|
||||||
break;
|
} else {
|
||||||
default:
|
|
||||||
d->m_foldingState = Internal::Header;
|
d->m_foldingState = Internal::Header;
|
||||||
TextEditor::TextDocumentLayout::setFoldingIndent(currentBlock(), BASE_LEVEL);
|
TextEditor::TextDocumentLayout::setFoldingIndent(currentBlock(), BASE_LEVEL);
|
||||||
break;
|
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case Internal::File:
|
case Internal::File:
|
||||||
switch (format) {
|
if (format == TextEditor::C_DIFF_FILE) {
|
||||||
case Internal::DiffFileFormat:
|
|
||||||
TextEditor::TextDocumentLayout::setFoldingIndent(currentBlock(), FILE_LEVEL);
|
TextEditor::TextDocumentLayout::setFoldingIndent(currentBlock(), FILE_LEVEL);
|
||||||
break;
|
} else if (format == TextEditor::C_DIFF_LOCATION) {
|
||||||
case Internal::DiffLocationFormat:
|
|
||||||
d->m_foldingState = Internal::Location;
|
d->m_foldingState = Internal::Location;
|
||||||
TextEditor::TextDocumentLayout::setFoldingIndent(currentBlock(), FILE_LEVEL);
|
TextEditor::TextDocumentLayout::setFoldingIndent(currentBlock(), FILE_LEVEL);
|
||||||
break;
|
} else {
|
||||||
default:
|
|
||||||
TextEditor::TextDocumentLayout::setFoldingIndent(currentBlock(), FILE_LEVEL);
|
TextEditor::TextDocumentLayout::setFoldingIndent(currentBlock(), FILE_LEVEL);
|
||||||
break;
|
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case Internal::Location:
|
case Internal::Location:
|
||||||
switch (format) {
|
if (format == TextEditor::C_DIFF_FILE) {
|
||||||
case Internal::DiffFileFormat:
|
|
||||||
d->m_foldingState = Internal::File;
|
d->m_foldingState = Internal::File;
|
||||||
TextEditor::TextDocumentLayout::setFoldingIndent(currentBlock(), BASE_LEVEL);
|
TextEditor::TextDocumentLayout::setFoldingIndent(currentBlock(), BASE_LEVEL);
|
||||||
break;
|
} else if (format == TextEditor::C_DIFF_LOCATION) {
|
||||||
case Internal::DiffLocationFormat:
|
|
||||||
TextEditor::TextDocumentLayout::setFoldingIndent(currentBlock(), FILE_LEVEL);
|
TextEditor::TextDocumentLayout::setFoldingIndent(currentBlock(), FILE_LEVEL);
|
||||||
break;
|
} else {
|
||||||
default:
|
|
||||||
TextEditor::TextDocumentLayout::setFoldingIndent(currentBlock(), LOCATION_LEVEL);
|
TextEditor::TextDocumentLayout::setFoldingIndent(currentBlock(), LOCATION_LEVEL);
|
||||||
break;
|
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -32,6 +32,8 @@
|
|||||||
#include <QSyntaxHighlighter>
|
#include <QSyntaxHighlighter>
|
||||||
#include <texteditor/texteditorconstants.h>
|
#include <texteditor/texteditorconstants.h>
|
||||||
|
|
||||||
|
#include <functional>
|
||||||
|
|
||||||
namespace TextEditor {
|
namespace TextEditor {
|
||||||
|
|
||||||
class SyntaxHighlighter : public QSyntaxHighlighter
|
class SyntaxHighlighter : public QSyntaxHighlighter
|
||||||
@@ -43,7 +45,7 @@ public:
|
|||||||
protected:
|
protected:
|
||||||
void applyFormatToSpaces(const QString &, const QTextCharFormat &)
|
void applyFormatToSpaces(const QString &, const QTextCharFormat &)
|
||||||
{}
|
{}
|
||||||
void setTextFormatCategories(const QVector<TextEditor::TextStyle> &)
|
void setTextFormatCategories(int, std::function<TextStyle(int)>)
|
||||||
{}
|
{}
|
||||||
QTextCharFormat formatForCategory(int categoryIndex) const;
|
QTextCharFormat formatForCategory(int categoryIndex) const;
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user