aboutsummaryrefslogtreecommitdiffstats
path: root/src/plugins/git/githighlighters.cpp
diff options
context:
space:
mode:
authorOrgad Shaneh <orgad.shaneh@audiocodes.com>2013-06-02 23:05:51 +0300
committerOrgad Shaneh <orgads@gmail.com>2013-06-03 10:40:32 +0200
commit3f1901cb1f42c896d9f256937c5a3a4ceeca4501 (patch)
tree3b07fe677f5993be8e80201414e04ed8e4eb16f5 /src/plugins/git/githighlighters.cpp
parent3e022beb1235cf74cc2bbe30711858bf5c47d433 (diff)
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>
Diffstat (limited to 'src/plugins/git/githighlighters.cpp')
-rw-r--r--src/plugins/git/githighlighters.cpp56
1 files changed, 56 insertions, 0 deletions
diff --git a/src/plugins/git/githighlighters.cpp b/src/plugins/git/githighlighters.cpp
index d223a5e524..2f00c9f2db 100644
--- a/src/plugins/git/githighlighters.cpp
+++ b/src/plugins/git/githighlighters.cpp
@@ -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 &regexp,
+ 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