forked from qt-creator/qt-creator
Git: Fix commit message highlighting
Task-number: QTCREATORBUG-5874 Change-Id: I287a7fbd2d1a3c39983d7a9ac820b190250a6484 Reviewed-by: Tobias Hunger <tobias.hunger@digia.com>
This commit is contained in:
committed by
Orgad Shaneh
parent
40d001694b
commit
fafe964c71
@@ -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:
|
|||||||
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) :
|
|||||||
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 None:
|
||||||
|
break;
|
||||||
case Header: {
|
case Header: {
|
||||||
QTextCharFormat charFormat = format(0);
|
QTextCharFormat charFormat = format(0);
|
||||||
charFormat.setFontWeight(QFont::Bold);
|
charFormat.setFontWeight(QFont::Bold);
|
||||||
setFormat(0, text.size(), charFormat);
|
setFormat(0, text.size(), charFormat);
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
break;
|
|
||||||
case Comment:
|
|
||||||
setFormat(0, text.size(), m_commentFormat);
|
|
||||||
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) {
|
||||||
|
|||||||
Reference in New Issue
Block a user