Fix latex syntax highlighting with Qt6

This commit is contained in:
Enrico Forestieri 2021-03-17 10:17:10 +01:00
parent 968be3f209
commit 34ffa80c4c

View File

@ -132,12 +132,12 @@ void LaTeXHighlighter::highlightBlock(QString const & text)
// $ $ // $ $
static const QRegularExpression exprMath("\\$[^\\$]*\\$"); static const QRegularExpression exprMath("\\$[^\\$]*\\$");
QRegularExpressionMatch match = exprMath.match(text); QRegularExpressionMatch match = exprMath.match(text);
int index = match.capturedStart(1); int index = match.capturedStart(0);
while (index >= 0) { while (index >= 0) {
int length = match.capturedEnd(1) - index; int length = match.capturedLength(0);
setFormat(index, length, mathFormat); setFormat(index, length, mathFormat);
match = exprMath.match(text, index + length); match = exprMath.match(text, index + length);
index = match.capturedStart(1); index = match.capturedStart(0);
} }
// [ ] // [ ]
static const QRegularExpression exprStartDispMath("(\\\\\\[|" static const QRegularExpression exprStartDispMath("(\\\\\\[|"
@ -166,21 +166,21 @@ void LaTeXHighlighter::highlightBlock(QString const & text)
// otherwise, start search from 'begin disp math' // otherwise, start search from 'begin disp math'
if (previousBlockState() != 1) { if (previousBlockState() != 1) {
match = exprStartDispMath.match(text); match = exprStartDispMath.match(text);
startIndex = match.capturedStart(1); startIndex = match.capturedStart(0);
} }
while (startIndex >= 0) { while (startIndex >= 0) {
match = exprEndDispMath.match(text, startIndex); match = exprEndDispMath.match(text, startIndex);
int endIndex = match.capturedStart(1); int endIndex = match.capturedStart(0);
int length; int length;
if (endIndex == -1) { if (endIndex == -1) {
setCurrentBlockState(1); setCurrentBlockState(1);
length = text.length() - startIndex; length = text.length() - startIndex;
} else { } else {
length = match.capturedEnd(1) - startIndex; length = endIndex - startIndex + match.capturedLength(0);
} }
setFormat(startIndex, length, mathFormat); setFormat(startIndex, length, mathFormat);
match = exprStartDispMath.match(text, startIndex + length); match = exprStartDispMath.match(text, startIndex + length);
startIndex = match.capturedStart(1); startIndex = match.capturedStart(0);
} }
// \whatever // \whatever
static const QRegularExpression exprKeywordAtOther("\\\\[A-Za-z]+"); static const QRegularExpression exprKeywordAtOther("\\\\[A-Za-z]+");
@ -189,12 +189,12 @@ void LaTeXHighlighter::highlightBlock(QString const & text)
QRegularExpression const & exprKeyword = at_letter_ QRegularExpression const & exprKeyword = at_letter_
? exprKeywordAtLetter : exprKeywordAtOther; ? exprKeywordAtLetter : exprKeywordAtOther;
match = exprKeyword.match(text); match = exprKeyword.match(text);
index = match.capturedStart(1); index = match.capturedStart(0);
while (index >= 0) { while (index >= 0) {
int length = match.capturedEnd(1) - index; int length = match.capturedLength(0);
setFormat(index, length, keywordFormat); setFormat(index, length, keywordFormat);
match = exprKeyword.match(text, index + length); match = exprKeyword.match(text, index + length);
index = match.capturedStart(1); index = match.capturedStart(0);
} }
// %comment // %comment
// Treat a line as a comment starting at a percent sign // Treat a line as a comment starting at a percent sign
@ -206,7 +206,7 @@ void LaTeXHighlighter::highlightBlock(QString const & text)
match = exprComment.match(text); match = exprComment.match(text);
index = match.capturedStart(1); index = match.capturedStart(1);
while (index >= 0) { while (index >= 0) {
int const length = match.capturedEnd(1) - index int const length = match.capturedLength(0)
- (index - match.capturedStart(0)); - (index - match.capturedStart(0));
setFormat(index, length, commentFormat); setFormat(index, length, commentFormat);
match = exprComment.match(text, index + length); match = exprComment.match(text, index + length);
@ -216,12 +216,12 @@ void LaTeXHighlighter::highlightBlock(QString const & text)
QString lyxwarn = qt_("LyX Warning: "); QString lyxwarn = qt_("LyX Warning: ");
QRegularExpression exprWarning("<" + lyxwarn + "[^<]*>"); QRegularExpression exprWarning("<" + lyxwarn + "[^<]*>");
match = exprWarning.match(text); match = exprWarning.match(text);
index = match.capturedStart(1); index = match.capturedStart(0);
while (index >= 0) { while (index >= 0) {
int length = match.capturedEnd(1) - index; int length = match.capturedLength(0);
setFormat(index, length, warningFormat); setFormat(index, length, warningFormat);
match = exprWarning.match(text, index + length); match = exprWarning.match(text, index + length);
index = match.capturedStart(1); index = match.capturedStart(0);
} }
#endif #endif
} }