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

Mercurial: Fix highlighting


* Hash is not a comment, "HG:" is.
* First line *that is not a comment* is a summary

Change-Id: If4e3428bfd4461dc105583a998be5d8185be3ab6
Reviewed-by: default avatarChristian Stenger <christian.stenger@digia.com>
parent f0a6345f
No related branches found
No related tags found
No related merge requests found
......@@ -36,12 +36,10 @@
#include <texteditor/texteditorconstants.h>
#include <utils/qtcassert.h>
#include <QRegExp>
#include <QSyntaxHighlighter>
#include <QTextEdit>
#include <QDebug>
#include <QRegExp>
//see the git submit widget for details of the syntax Highlighter
namespace Mercurial {
......@@ -57,16 +55,14 @@ public:
void highlightBlock(const QString &text);
private:
enum State { Header, Comment, Other };
enum State { None = -1, Header, Other };
enum Format { Format_Comment };
QRegExp m_keywordPattern;
const QChar m_hashChar;
};
MercurialSubmitHighlighter::MercurialSubmitHighlighter(QTextEdit *parent) :
TextEditor::SyntaxHighlighter(parent),
m_keywordPattern(QLatin1String("^\\w+:")),
m_hashChar(QLatin1Char('#'))
m_keywordPattern(QLatin1String("^\\w+:"))
{
static QVector<TextEditor::TextStyle> categories;
if (categories.isEmpty())
......@@ -79,25 +75,35 @@ MercurialSubmitHighlighter::MercurialSubmitHighlighter(QTextEdit *parent) :
void MercurialSubmitHighlighter::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.startsWith(QLatin1String("HG:"))) {
setFormat(0, text.size(), formatForCategory(Format_Comment));
setCurrentBlockState(state);
return;
}
if (state == None) {
if (text.isEmpty()) {
setCurrentBlockState(state);
return;
}
state = Header;
} else {
if (text.startsWith(m_hashChar))
state = Comment;
} else if (state == Header) {
state = Other;
}
setCurrentBlockState(state);
// Apply format.
switch (state) {
case None:
break;
case Header: {
QTextCharFormat charFormat = format(0);
charFormat.setFontWeight(QFont::Bold);
setFormat(0, text.size(), charFormat);
break;
}
case Comment:
setFormat(0, text.size(), formatForCategory(Format_Comment));
break;
case Other:
// Format key words ("Task:") italic
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