Skip to content
Snippets Groups Projects
Commit fafe964c authored by Orgad Shaneh's avatar Orgad Shaneh Committed by Orgad Shaneh
Browse files

Git: Fix commit message highlighting


Task-number: QTCREATORBUG-5874
Change-Id: I287a7fbd2d1a3c39983d7a9ac820b190250a6484
Reviewed-by: default avatarTobias Hunger <tobias.hunger@digia.com>
parent 40d00169
No related branches found
No related tags found
No related merge requests found
...@@ -62,7 +62,7 @@ public: ...@@ -62,7 +62,7 @@ public:
void highlightBlock(const QString &text); void highlightBlock(const QString &text);
private: private:
enum State { Header, Comment, Other }; enum State { None = -1, Header, Other };
const QTextCharFormat m_commentFormat; const QTextCharFormat m_commentFormat;
QRegExp m_keywordPattern; QRegExp m_keywordPattern;
const QChar m_hashChar; const QChar m_hashChar;
...@@ -71,7 +71,7 @@ private: ...@@ -71,7 +71,7 @@ private:
GitSubmitHighlighter::GitSubmitHighlighter(QTextEdit * parent) : GitSubmitHighlighter::GitSubmitHighlighter(QTextEdit * parent) :
QSyntaxHighlighter(parent), QSyntaxHighlighter(parent),
m_commentFormat(commentFormat()), m_commentFormat(commentFormat()),
m_keywordPattern(QLatin1String("^\\w+:")), m_keywordPattern(QLatin1String("^[\\w-]+:")),
m_hashChar(QLatin1Char('#')) m_hashChar(QLatin1Char('#'))
{ {
QTC_CHECK(m_keywordPattern.isValid()); QTC_CHECK(m_keywordPattern.isValid());
...@@ -80,25 +80,30 @@ GitSubmitHighlighter::GitSubmitHighlighter(QTextEdit * parent) : ...@@ -80,25 +80,30 @@ GitSubmitHighlighter::GitSubmitHighlighter(QTextEdit * parent) :
void GitSubmitHighlighter::highlightBlock(const QString &text) void GitSubmitHighlighter::highlightBlock(const QString &text)
{ {
// figure out current state // figure out current state
State state = Other; State state = static_cast<State>(previousBlockState());
const QTextBlock block = currentBlock(); if (text.isEmpty()) {
if (block.position() == 0) { if (state == Header)
state = Other;
setCurrentBlockState(state);
return;
} else if (text.startsWith(m_hashChar)) {
setFormat(0, text.size(), m_commentFormat);
return;
} else if (state == None) {
state = Header; state = Header;
} else {
if (text.startsWith(m_hashChar))
state = Comment;
} }
setCurrentBlockState(state);
// Apply format. // Apply format.
switch (state) { switch (state) {
case Header: { case None:
QTextCharFormat charFormat = format(0);
charFormat.setFontWeight(QFont::Bold);
setFormat(0, text.size(), charFormat);
}
break; break;
case Comment: case Header: {
setFormat(0, text.size(), m_commentFormat); QTextCharFormat charFormat = format(0);
charFormat.setFontWeight(QFont::Bold);
setFormat(0, text.size(), charFormat);
break; break;
}
case Other: case Other:
// Format key words ("Task:") italic // Format key words ("Task:") italic
if (m_keywordPattern.indexIn(text, 0, QRegExp::CaretAtZero) == 0) { if (m_keywordPattern.indexIn(text, 0, QRegExp::CaretAtZero) == 0) {
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment