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
......@@ -62,7 +62,7 @@ public:
void highlightBlock(const QString &text);
private:
enum State { Header, Comment, Other };
enum State { None = -1, Header, Other };
const QTextCharFormat m_commentFormat;
QRegExp m_keywordPattern;
const QChar m_hashChar;
......@@ -71,7 +71,7 @@ private:
GitSubmitHighlighter::GitSubmitHighlighter(QTextEdit * parent) :
QSyntaxHighlighter(parent),
m_commentFormat(commentFormat()),
m_keywordPattern(QLatin1String("^\\w+:")),
m_keywordPattern(QLatin1String("^[\\w-]+:")),
m_hashChar(QLatin1Char('#'))
{
QTC_CHECK(m_keywordPattern.isValid());
......@@ -80,25 +80,30 @@ GitSubmitHighlighter::GitSubmitHighlighter(QTextEdit * parent) :
void GitSubmitHighlighter::highlightBlock(const QString &text)
{
// figure out current state
State state = Other;
const QTextBlock block = currentBlock();
if (block.position() == 0) {
State state = static_cast<State>(previousBlockState());
if (text.isEmpty()) {
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;
} else {
if (text.startsWith(m_hashChar))
state = Comment;
}
setCurrentBlockState(state);
// Apply format.
switch (state) {
case Header: {
QTextCharFormat charFormat = format(0);
charFormat.setFontWeight(QFont::Bold);
setFormat(0, text.size(), charFormat);
}
case None:
break;
case Comment:
setFormat(0, text.size(), m_commentFormat);
case Header: {
QTextCharFormat charFormat = format(0);
charFormat.setFontWeight(QFont::Bold);
setFormat(0, text.size(), charFormat);
break;
}
case Other:
// Format key words ("Task:") italic
if (m_keywordPattern.indexIn(text, 0, QRegExp::CaretAtZero) == 0) {
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment