aboutsummaryrefslogtreecommitdiffstats
path: root/src/plugins/mercurial
diff options
context:
space:
mode:
authorOrgad Shaneh <orgad.shaneh@audiocodes.com>2014-11-04 22:45:25 +0200
committerOrgad Shaneh <orgads@gmail.com>2014-11-05 09:47:38 +0100
commitc456968b076654f1d3605e8d1f2f5d156ec831c5 (patch)
tree2b1a923995a69ce44df87237ce33500465771a4b /src/plugins/mercurial
parentf0a6345fdeed44336932389189749b94188566ce (diff)
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: Christian Stenger <christian.stenger@digia.com>
Diffstat (limited to 'src/plugins/mercurial')
-rw-r--r--src/plugins/mercurial/mercurialcommitwidget.cpp38
1 files changed, 22 insertions, 16 deletions
diff --git a/src/plugins/mercurial/mercurialcommitwidget.cpp b/src/plugins/mercurial/mercurialcommitwidget.cpp
index 1d3a683012..28667434d9 100644
--- a/src/plugins/mercurial/mercurialcommitwidget.cpp
+++ b/src/plugins/mercurial/mercurialcommitwidget.cpp
@@ -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) {