From 718b94f3f0caa1797f35ca0a5d3160dcd7b5150a Mon Sep 17 00:00:00 2001 From: Fabio Bas Date: Mon, 25 Oct 2010 07:43:21 +0000 Subject: fix for #992 git-svn-id: https://svn.kvirc.de/svn/trunk/kvirc@5107 17fca916-40b9-46aa-a4ea-0a15b648b75c --- src/modules/editor/scripteditor.cpp | 123 +++++++++++++++++++++++------------- 1 file changed, 78 insertions(+), 45 deletions(-) (limited to 'src/modules') diff --git a/src/modules/editor/scripteditor.cpp b/src/modules/editor/scripteditor.cpp index 2d5a47ea0..86ab06632 100644 --- a/src/modules/editor/scripteditor.cpp +++ b/src/modules/editor/scripteditor.cpp @@ -578,7 +578,6 @@ KviScriptEditorSyntaxHighlighter::KviScriptEditorSyntaxHighlighter(KviScriptEdit // FIX-ME: "function ..." - "function internal ..." // FIX-ME: "@$" // FIX-ME: "\" escape char - // FIX-ME: comment multiline with empty line updateSyntaxtTextFormat(); KviScriptHighlightingRule rule; @@ -603,13 +602,6 @@ KviScriptEditorSyntaxHighlighter::KviScriptEditorSyntaxHighlighter(KviScriptEdit rule.pattern=QRegExp("([{}])+"); rule.format=bracketFormat; highlightingRules.append(rule); - - rule.pattern=QRegExp("(//[^\\n]*)|(#[^\\n]*)"); - rule.format=commentFormat; - highlightingRules.append(rule); - - commentStartExpression = QRegExp("/\\*"); - commentEndExpression = QRegExp("\\*/"); } KviScriptEditorSyntaxHighlighter::~KviScriptEditorSyntaxHighlighter() @@ -627,6 +619,17 @@ void KviScriptEditorSyntaxHighlighter::updateSyntaxtTextFormat() findFormat.setForeground(g_clrFind); } +#define SKIP_SPACES \ + while(iIndexStart < szText.size()) \ + { \ + if(szText.at(iIndexStart).unicode()=='\t' || szText.at(iIndexStart).unicode()==' ') \ + { \ + iIndexStart++; \ + } else { \ + break; \ + } \ + } \ + void KviScriptEditorSyntaxHighlighter::highlightBlock(const QString & szText) { if(szText.isEmpty()) @@ -636,8 +639,8 @@ void KviScriptEditorSyntaxHighlighter::highlightBlock(const QString & szText) if(previousBlockState() == 1) { - // in comment - int iCommentEnd = szText.indexOf(commentEndExpression); + // inside a multiline comment + int iCommentEnd = szText.indexOf("*/"); if(iCommentEnd < 0) { // not found: comment until the end of the block @@ -645,35 +648,86 @@ void KviScriptEditorSyntaxHighlighter::highlightBlock(const QString & szText) setFormat(iIndexStart,szText.length(),commentFormat); return; } + // skip 2 chars + iCommentEnd+=2; // end of comment found setFormat(iIndexStart,iCommentEnd - iIndexStart,commentFormat); setCurrentBlockState(0); iIndexStart = iCommentEnd; } - // skip tabulations and spaces - while(iIndexStart < szText.size()) - { - if(szText.at(iIndexStart).unicode()=='\t' || szText.at(iIndexStart).unicode()==' ') - { - iIndexStart++; - } else { - break; - } - } + SKIP_SPACES if (iIndexStart == szText.size()) return; - // check 'commands' + // check 'commands' and comments int iCommandStart=iIndexStart; if (szText.at(iIndexStart).unicode()!='$' && szText.at(iIndexStart).unicode()!='{' && szText.at(iIndexStart).unicode()!='}' && szText.at(iIndexStart).unicode()!='%') { - while(iIndexStart= 0) - { - int endIndex = szText.indexOf(commentEndExpression, startIndex); - int commentLength; - if (endIndex == -1) - { - setCurrentBlockState(1); - commentLength = szText.length() - startIndex; - } else { - commentLength = endIndex - startIndex + commentEndExpression.matchedLength(); - } - setFormat(startIndex, commentLength, commentFormat); - startIndex = szText.indexOf(commentStartExpression, startIndex + commentLength); - } - // 'found matches' highlighting KviScriptEditorWidget * pEditor = ((KviScriptEditorWidget *)textEdit()); QString szFind = pEditor->m_szFind; -- cgit v1.3.1-10-gc9f91