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