LaTeXHighlighter: handle grouped values with commas in keyval options

This commit is contained in:
Juergen Spitzmueller 2023-07-18 17:35:48 +02:00
parent 9e308ddb03
commit eadc8ab147

View File

@ -50,6 +50,7 @@ void LaTeXHighlighter::highlightBlock(QString const & text)
if (keyval_) { if (keyval_) {
// Highlight key-val options. Used in some option widgets. // Highlight key-val options. Used in some option widgets.
static QRegularExpression exprKeyvalkey("[^=,]+"); static QRegularExpression exprKeyvalkey("[^=,]+");
static QRegularExpression exprKeyvalgval("[^,]+{[^}]+}");
static QRegularExpression exprKeyvalval("[^,]+"); static QRegularExpression exprKeyvalval("[^,]+");
if (optsnippet_) { if (optsnippet_) {
static QRegularExpression exprKeyvalkey("^=,+"); static QRegularExpression exprKeyvalkey("^=,+");
@ -61,15 +62,24 @@ void LaTeXHighlighter::highlightBlock(QString const & text)
int length = matchkey.capturedLength(0); int length = matchkey.capturedLength(0);
setFormat(kvindex, length, keyFormat); setFormat(kvindex, length, keyFormat);
if (text.size() > kvindex + length && text.at(kvindex + length) == '=') { if (text.size() > kvindex + length && text.at(kvindex + length) == '=') {
QRegularExpressionMatch matchgval =
exprKeyvalgval.match(text, kvindex + length);
int kvvindex = matchgval.capturedStart(0);
if (kvvindex > 0) {
int vlength = matchgval.capturedLength(0);
length += vlength;
setFormat(kvvindex, vlength, valFormat);
} else {
QRegularExpressionMatch matchval = QRegularExpressionMatch matchval =
exprKeyvalval.match(text, kvindex + length); exprKeyvalval.match(text, kvindex + length);
int kvvindex = matchval.capturedStart(0); kvvindex = matchval.capturedStart(0);
if (kvvindex > 0) { if (kvvindex > 0) {
int vlength = matchval.capturedLength(0); int vlength = matchval.capturedLength(0);
length += vlength; length += vlength;
setFormat(kvvindex, vlength, valFormat); setFormat(kvvindex, vlength, valFormat);
} }
} }
}
matchkey = exprKeyvalkey.match(text, kvindex + length); matchkey = exprKeyvalkey.match(text, kvindex + length);
kvindex = matchkey.capturedStart(0); kvindex = matchkey.capturedStart(0);
} }