forked from qt-creator/qt-creator
Git: Provide a real highlighter for interactive rebase
* Kate highlighter doesn't have enough colors * It works out of the box only on Windows * New editor support links Change-Id: I09bbaef08574660e535ccb86c2c460d5976fc2e3 Reviewed-by: Tobias Hunger <tobias.hunger@digia.com>
This commit is contained in:
committed by
Orgad Shaneh
parent
3e022beb12
commit
3f1901cb1f
@@ -38,6 +38,8 @@
|
||||
namespace Git {
|
||||
namespace Internal {
|
||||
|
||||
static const char CHANGE_PATTERN[] = "\\b[a-f0-9]{7,40}\\b";
|
||||
|
||||
// Retrieve the comment char format from the text editor.
|
||||
static QTextCharFormat commentFormat()
|
||||
{
|
||||
@@ -104,5 +106,59 @@ void GitSubmitHighlighter::highlightBlock(const QString &text)
|
||||
}
|
||||
}
|
||||
|
||||
GitRebaseHighlighter::RebaseAction::RebaseAction(const QString ®exp,
|
||||
const TextEditor::FontSettings &settings,
|
||||
TextEditor::TextStyle category)
|
||||
: exp(regexp)
|
||||
{
|
||||
format = settings.toTextCharFormat(category);
|
||||
}
|
||||
|
||||
GitRebaseHighlighter::GitRebaseHighlighter(TextEditor::BaseTextDocument *parent) :
|
||||
TextEditor::SyntaxHighlighter(parent),
|
||||
m_hashChar(QLatin1Char('#')),
|
||||
m_changeNumberPattern(QLatin1String(CHANGE_PATTERN))
|
||||
{
|
||||
const TextEditor::FontSettings settings = TextEditor::TextEditorSettings::instance()->fontSettings();
|
||||
m_commentFormat = settings.toTextCharFormat(TextEditor::C_COMMENT);
|
||||
m_changeFormat = settings.toTextCharFormat(TextEditor::C_DOXYGEN_COMMENT);
|
||||
m_descFormat = settings.toTextCharFormat(TextEditor::C_STRING);
|
||||
m_actions << RebaseAction(QLatin1String("^(p|pick)\\b"), settings, TextEditor::C_KEYWORD);
|
||||
m_actions << RebaseAction(QLatin1String("^(r|reword)\\b"), settings, TextEditor::C_FIELD);
|
||||
m_actions << RebaseAction(QLatin1String("^(e|edit)\\b"), settings, TextEditor::C_TYPE);
|
||||
m_actions << RebaseAction(QLatin1String("^(s|squash)\\b"), settings, TextEditor::C_ENUMERATION);
|
||||
m_actions << RebaseAction(QLatin1String("^(f|fixup)\\b"), settings, TextEditor::C_NUMBER);
|
||||
m_actions << RebaseAction(QLatin1String("^(x|exec)\\b"), settings, TextEditor::C_LABEL);
|
||||
}
|
||||
|
||||
void GitRebaseHighlighter::highlightBlock(const QString &text)
|
||||
{
|
||||
if (text.startsWith(m_hashChar)) {
|
||||
setFormat(0, text.size(), m_commentFormat);
|
||||
int changeIndex = 0;
|
||||
while ((changeIndex = m_changeNumberPattern.indexIn(text, changeIndex)) != -1) {
|
||||
const int changeLen = m_changeNumberPattern.matchedLength();
|
||||
setFormat(changeIndex, changeLen, m_changeFormat);
|
||||
changeIndex += changeLen;
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
foreach (const RebaseAction &action, m_actions) {
|
||||
if (action.exp.indexIn(text) != -1) {
|
||||
const int len = action.exp.matchedLength();
|
||||
setFormat(0, len, action.format);
|
||||
const int changeIndex = m_changeNumberPattern.indexIn(text, len);
|
||||
if (changeIndex != -1) {
|
||||
const int changeLen = m_changeNumberPattern.matchedLength();
|
||||
const int descStart = changeIndex + changeLen + 1;
|
||||
setFormat(changeIndex, changeLen, m_changeFormat);
|
||||
setFormat(descStart, text.size() - descStart, m_descFormat);
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
} // namespace Internal
|
||||
} // namespace Git
|
||||
|
||||
Reference in New Issue
Block a user