[LyX/master] Improve keyval highlighter
Juergen Spitzmueller
spitz at lyx.org
Tue Jul 18 13:53:07 UTC 2023
commit 9e308ddb0323719152d97371e0ab0ee80c318010
Author: Juergen Spitzmueller <spitz at lyx.org>
Date: Tue Jul 18 17:05:56 2023 +0200
Improve keyval highlighter
---
src/frontends/qt/LaTeXHighlighter.cpp | 26 ++++++++++++++++----------
1 files changed, 16 insertions(+), 10 deletions(-)
diff --git a/src/frontends/qt/LaTeXHighlighter.cpp b/src/frontends/qt/LaTeXHighlighter.cpp
index 9e24c72..1fa31a1 100644
--- a/src/frontends/qt/LaTeXHighlighter.cpp
+++ b/src/frontends/qt/LaTeXHighlighter.cpp
@@ -44,25 +44,31 @@ LaTeXHighlighter::LaTeXHighlighter(QTextDocument * parent, bool at_letter, bool
}
-void LaTeXHighlighter::highlightBlock(QString const & text_in)
+void LaTeXHighlighter::highlightBlock(QString const & text)
{
- QString const text = (optsnippet_) ? '[' + text_in + ']' : text_in;
// keyval
if (keyval_) {
// Highlight key-val options. Used in some option widgets.
- static const QRegularExpression exprKeyvalkey("[^=,]+");
- static const QRegularExpression exprKeyvalval("[^,]+");
+ static QRegularExpression exprKeyvalkey("[^=,]+");
+ static QRegularExpression exprKeyvalval("[^,]+");
+ if (optsnippet_) {
+ static QRegularExpression exprKeyvalkey("^=,+");
+ static QRegularExpression exprKeyvalval("^,+");
+ }
QRegularExpressionMatch matchkey = exprKeyvalkey.match(text);
int kvindex = matchkey.capturedStart(0);
while (kvindex >= 0) {
int length = matchkey.capturedLength(0);
setFormat(kvindex, length, keyFormat);
- QRegularExpressionMatch matchval =
- exprKeyvalval.match(text, kvindex + length);
- int kvvindex = matchval.capturedStart(0);
- if (kvvindex > 0) {
- length += matchval.capturedLength(0);
- setFormat(kvvindex, length, valFormat);
+ if (text.size() > kvindex + length && text.at(kvindex + length) == '=') {
+ QRegularExpressionMatch matchval =
+ exprKeyvalval.match(text, kvindex + length);
+ int 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);
More information about the lyx-cvs
mailing list