0
0
mirror of https://github.com/fralx/LimeReport.git synced 2024-12-24 00:33:02 +03:00

Merge pull request #333 from makarenkov/code-editor-fixes

Script highlighter fixes
This commit is contained in:
Alexander Arin 2021-06-22 18:39:24 +03:00 committed by GitHub
commit ca8ce0fdc9
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -34,7 +34,7 @@ enum LiteralsType {
}; };
enum States { enum States {
Undefinded = -1, Undefined = -1,
Start, Start,
MayBeKeyWord, MayBeKeyWord,
Code, Code,
@ -67,8 +67,8 @@ void ScriptHighlighter::highlightBlock(const QString& text)
int literal = -1; int literal = -1;
bool lastWasBackSlash = false; bool lastWasBackSlash = false;
States prevState = (States)previousBlockState(); States prevState = (States)previousBlockState();
States state = prevState != Undefinded ? (States)prevState : Start; States state = prevState != Undefined ? (States)prevState : Start;
States oldState = Undefinded; States oldState = Undefined;
const States stateMaschine[StatesCount][LiteralsCount] = { const States stateMaschine[StatesCount][LiteralsCount] = {
// Space Alpahabet Number Hash Slash Asterix, Bracket, Quotation, Apostrophe, Apostrophe2 Separator, Back Slash // 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}, {Separator, MayBeKeyWord, MayBeNumber, Separator, MayBeComment, Separator, Separator, String, String2, String3, Separator, Separator},
@ -87,7 +87,7 @@ void ScriptHighlighter::highlightBlock(const QString& text)
QString buffer; QString buffer;
setCurrentBlockState(Undefinded); setCurrentBlockState(Undefined);
if (text.isEmpty()) if (text.isEmpty())
{ {
@ -172,7 +172,7 @@ void ScriptHighlighter::highlightBlock(const QString& text)
switch(oldState){ switch(oldState){
case MayBeComment2End: case MayBeComment2End:
setFormat(i-(buffer.length()-1), buffer.length(), m_formats[CommentFormat]); setFormat(i-(buffer.length()-1), buffer.length(), m_formats[CommentFormat]);
setCurrentBlockState(Undefinded); setCurrentBlockState(Undefined);
buffer.clear(); buffer.clear();
break; break;
case MayBeKeyWord: case MayBeKeyWord:
@ -214,11 +214,15 @@ void ScriptHighlighter::highlightBlock(const QString& text)
if (buffer.length()) if (buffer.length())
{ {
if (oldState == MayBeKeyWord) if (state == MayBeKeyWord)
{ {
if (isKeyWord(buffer)) 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; TextBlockData *data = new TextBlockData;