From 6bfc6be9fbb2839a177f29a889863fda5c3d6d24 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=9A=D0=BE=D0=BD=D1=81=D1=82=D0=B0=D0=BD=D1=82=D0=B8?= =?UTF-8?q?=D0=BD=20=D0=9C=D0=B0=D0=BA=D0=B0=D1=80=D0=B5=D0=BD=D0=BA=D0=BE?= =?UTF-8?q?=D0=B2?= Date: Fri, 18 Jun 2021 16:04:39 +0300 Subject: [PATCH] Script highlighter fixes Fixed: keywords and numbers at the end of the line were not highlighted --- .../scripteditor/lrscripthighlighter.cpp | 20 +++++++++++-------- 1 file changed, 12 insertions(+), 8 deletions(-) diff --git a/limereport/scripteditor/lrscripthighlighter.cpp b/limereport/scripteditor/lrscripthighlighter.cpp index 87a0aa5..a3aaf48 100644 --- a/limereport/scripteditor/lrscripthighlighter.cpp +++ b/limereport/scripteditor/lrscripthighlighter.cpp @@ -34,7 +34,7 @@ enum LiteralsType { }; enum States { - Undefinded = -1, + Undefined = -1, Start, MayBeKeyWord, Code, @@ -67,8 +67,8 @@ void ScriptHighlighter::highlightBlock(const QString& text) int literal = -1; bool lastWasBackSlash = false; States prevState = (States)previousBlockState(); - States state = prevState != Undefinded ? (States)prevState : Start; - States oldState = Undefinded; + States state = prevState != Undefined ? (States)prevState : Start; + States oldState = Undefined; const States stateMaschine[StatesCount][LiteralsCount] = { // Space Alpahabet Number Hash Slash Asterix, Bracket, Quotation, Apostrophe, Apostrophe2 Separator, Back Slash {Separator, MayBeKeyWord, MayBeNumber, Separator, MayBeComment, Separator, Separator, String, String2, String3, Separator, Separator}, @@ -87,7 +87,7 @@ void ScriptHighlighter::highlightBlock(const QString& text) QString buffer; - setCurrentBlockState(Undefinded); + setCurrentBlockState(Undefined); if (text.isEmpty()) { @@ -172,7 +172,7 @@ void ScriptHighlighter::highlightBlock(const QString& text) switch(oldState){ case MayBeComment2End: setFormat(i-(buffer.length()-1), buffer.length(), m_formats[CommentFormat]); - setCurrentBlockState(Undefinded); + setCurrentBlockState(Undefined); buffer.clear(); break; case MayBeKeyWord: @@ -214,16 +214,20 @@ void ScriptHighlighter::highlightBlock(const QString& text) if (buffer.length()) { - if (oldState == MayBeKeyWord) + if (state == MayBeKeyWord) { if (isKeyWord(buffer)) - setFormat(i - buffer.length(), buffer.length(), m_formats[KeywordFormat]); + setFormat(i - buffer.length(), buffer.length(), m_formats[KeywordFormat]); + } + else if (state == MayBeNumber) + { + setFormat(i - buffer.length(), buffer.length(), m_formats[NumberFormat]); } } TextBlockData *data = new TextBlockData; - for (int i = 0; i < PARENHEIS_COUNT; ++i){ + for (int i = 0; i < PARENHEIS_COUNT; ++i) { createParentheisisInfo(parenthesisCharacters[LeftParenthesis][i].toLatin1(), data, text); createParentheisisInfo(parenthesisCharacters[RightParenthesis][i].toLatin1(), data, text); }