]> git.lyx.org Git - features.git/commitdiff
Correctly highlight comments in latexHighlighter
authorBo Peng <bpeng@lyx.org>
Mon, 26 Mar 2007 15:51:34 +0000 (15:51 +0000)
committerBo Peng <bpeng@lyx.org>
Mon, 26 Mar 2007 15:51:34 +0000 (15:51 +0000)
git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@17574 a592a061-630c-0410-9148-cb99ea01b6c8

src/frontends/qt4/QViewSource.C

index 2a75f4e26105285aa227e1e44a576257dc5d3c9f..5a7893ecc1826863c0c9c7b772a429a080421c2b 100644 (file)
@@ -32,17 +32,9 @@ latexHighlighter::latexHighlighter(QTextDocument * parent) :
 
 void latexHighlighter::highlightBlock(QString const & text)
 {
-       // comment
-       QRegExp exprComment("^%.*$");
-       int index = text.indexOf(exprComment);
-       while (index >= 0) {
-               int length = exprComment.matchedLength();
-               setFormat(index, length, commentFormat);
-               index = text.indexOf(exprComment, index + length);
-       }
        // $ $ 
        QRegExp exprMath("\\$[^\\$]*\\$");
-       index = text.indexOf(exprMath);
+       int index = text.indexOf(exprMath);
        while (index >= 0) {
                int length = exprMath.matchedLength();
                setFormat(index, length, mathFormat);
@@ -95,6 +87,14 @@ void latexHighlighter::highlightBlock(QString const & text)
                setFormat(index, length, keywordFormat);
                index = text.indexOf(exprKeyword, index + length);
        }
+       // comment
+       QRegExp exprComment("(^|[^\\\\])%.*$");
+       index = text.indexOf(exprComment);
+       while (index >= 0) {
+               int length = exprComment.matchedLength();
+               setFormat(index, length, commentFormat);
+               index = text.indexOf(exprComment, index + length);
+       }
 }