From 62a509fcac6a57014707ce1e5d1561d23749a3a9 Mon Sep 17 00:00:00 2001 From: Ken Moore Date: Tue, 6 Sep 2016 14:39:04 -0400 Subject: Add a new test.cpp file for checking C/C++ syntax stuff, and fix up the backwards highlighting routine when both a start and end character are in close proximity in teh middle of the search. --- src-qt5/desktop-utils/lumina-textedit/PlainTextEditor.cpp | 7 ++++--- src-qt5/desktop-utils/lumina-textedit/syntaxSupport.cpp | 2 +- src-qt5/desktop-utils/lumina-textedit/tests/test.cpp | 13 +++++++++++++ 3 files changed, 18 insertions(+), 4 deletions(-) create mode 100644 src-qt5/desktop-utils/lumina-textedit/tests/test.cpp (limited to 'src-qt5/desktop-utils') diff --git a/src-qt5/desktop-utils/lumina-textedit/PlainTextEditor.cpp b/src-qt5/desktop-utils/lumina-textedit/PlainTextEditor.cpp index 6f583e4e..82b742ec 100644 --- a/src-qt5/desktop-utils/lumina-textedit/PlainTextEditor.cpp +++ b/src-qt5/desktop-utils/lumina-textedit/PlainTextEditor.cpp @@ -166,17 +166,18 @@ void PlainTextEditor::highlightMatch(QChar ch, bool forward, int fromPos, QChar int tmpFromPos = fromPos; QString doc = this->toPlainText(); while( nested>0 && tmpFromPos=fromPos && forward) || ( tmpFromPos<=fromPos && !forward ) ) ){ - if(forward){ + if(forward){ QTextCursor cur = this->document()->find(ch, tmpFromPos); if(!cur.isNull()){ nested += doc.mid(tmpFromPos+1, cur.position()-tmpFromPos).count(startch) -1; if(nested==0){ matchright = cur.position(); } else{ tmpFromPos = cur.position(); } }else{ break; } - }else{ + }else{ QTextCursor cur = this->document()->find(ch, tmpFromPos, QTextDocument::FindBackward); if(!cur.isNull()){ - nested += doc.mid(cur.position(), tmpFromPos-cur.position()).count(startch) -1; + QString mid = doc.mid(cur.position()-1, tmpFromPos-cur.position()); + nested += mid.count(startch) - mid.count(ch); if(nested==0){ matchleft = cur.position(); } else{ tmpFromPos = cur.position()-1; } }else{ break; } diff --git a/src-qt5/desktop-utils/lumina-textedit/syntaxSupport.cpp b/src-qt5/desktop-utils/lumina-textedit/syntaxSupport.cpp index 3b4dd003..c13385d7 100644 --- a/src-qt5/desktop-utils/lumina-textedit/syntaxSupport.cpp +++ b/src-qt5/desktop-utils/lumina-textedit/syntaxSupport.cpp @@ -52,7 +52,7 @@ void Custom_Syntax::loadRules(QString type){ if(type=="C++"){ //Keywords (standard C/C++/Qt definitions) QStringList keywords; - keywords << "char" << "class" << "const" << "double" << "enum" << "explicit" << "extern" << "friend" << "inline" \ + keywords << "char" << "class" << "const" << "double" << "enum" << "explicit" << "extern" << "float" << "friend" << "inline" \ << "int" << "long" << "namespace" << "operator" << "private" << "protected" << "public" \ << "short" << "signals" << "signed" << "slots" << "static" << "struct" << "template" \ << "typedef" << "typename" << "union" << "unsigned" << "virtual" << "void" << "volatile" \ diff --git a/src-qt5/desktop-utils/lumina-textedit/tests/test.cpp b/src-qt5/desktop-utils/lumina-textedit/tests/test.cpp new file mode 100644 index 00000000..f78748bf --- /dev/null +++ b/src-qt5/desktop-utils/lumina-textedit/tests/test.cpp @@ -0,0 +1,13 @@ +Test(QString test){ + nestedFunction(){ } +} +if else done +return exit +bool float double + +some stuff // in-line comment + +some stuff /*multi +line +comment*/ +stuff -- cgit