diff --git a/NEWS.md b/NEWS.md index 521d3fbe..672b16b7 100644 --- a/NEWS.md +++ b/NEWS.md @@ -24,6 +24,7 @@ Red Panda C++ Version 2.27 - fix: Selected lines doesn't draw line break glyphs. - fix: issue #215 (Caret may be drawn in the gutter.) - change: Force use utf8 as the exec encoding for fmtlib in the auto link options page. + - fix: After spaces in comments and strings, symbol completion for '{' and '(' are wrong. Red Panda C++ Version 2.26 - enhancement: Code suggestion for embedded std::vectors. diff --git a/RedPandaIDE/editor.cpp b/RedPandaIDE/editor.cpp index dd23c4e1..4b53f09d 100644 --- a/RedPandaIDE/editor.cpp +++ b/RedPandaIDE/editor.cpp @@ -605,15 +605,15 @@ void Editor::undoSymbolCompletion(int pos) { QSynedit::PTokenAttribute attr; QString token; - bool tokenFinished; + QSynedit::SyntaxState syntaxState; if (!syntaxer()) return; if (!pSettings->editor().removeSymbolPairs()) return; - if (!getTokenAttriAtRowCol(caretXY(), token, tokenFinished, attr)) + if (!getTokenAttriAtRowCol(caretXY(), token, attr, syntaxState)) return; - if ((attr->tokenType() == QSynedit::TokenType::Comment) && (!tokenFinished)) + if (syntaxer()->isCommentNotFinished(syntaxState.state)) return ; //convert caret x to string index; pos--; @@ -745,7 +745,7 @@ void Editor::keyPressEvent(QKeyEvent *event) syntaxer()->setLine(s,caretY()); syntaxer()->nextToEol(); int state = syntaxer()->getState().state; - if (syntaxer()->isLastLineCommentNotFinished(state)) { + if (syntaxer()->isCommentNotFinished(state)) { if (s=="/**") { //javadoc style docstring s = lineText().mid(caretX()-1).trimmed(); if (s=="*/") { @@ -2543,9 +2543,9 @@ bool Editor::handleSymbolCompletion(QChar key) if (syntaxer()) { if (caretX() <= 1) { if (caretY()>1) { - if (syntaxer()->isLastLineCommentNotFinished(document()->getSyntaxState(caretY() - 2).state)) + if (syntaxer()->isCommentNotFinished(document()->getSyntaxState(caretY() - 2).state)) return false; - if (syntaxer()->isLastLineStringNotFinished(document()->getSyntaxState(caretY() - 2).state) + if (syntaxer()->isStringNotFinished(document()->getSyntaxState(caretY() - 2).state) && (key!='\"') && (key!='\'')) return false; } @@ -2554,11 +2554,11 @@ bool Editor::handleSymbolCompletion(QChar key) // Check if that line is highlighted as comment QSynedit::PTokenAttribute attr; QString token; - bool tokenFinished; - if (getTokenAttriAtRowCol(HighlightPos, token, tokenFinished, attr)) { - if ((attr->tokenType() == QSynedit::TokenType::Comment) && (!tokenFinished)) + QSynedit::SyntaxState syntaxState; + if (getTokenAttriAtRowCol(HighlightPos, token, attr, syntaxState)) { + if (syntaxer()->isCommentNotFinished(syntaxState.state)) return false; - if ((attr->tokenType() == QSynedit::TokenType::String) && (!tokenFinished) + if (syntaxer()->isStringNotFinished(syntaxState.state) && (key!='\'') && (key!='\"') && (key!='(') && (key!=')')) return false; if (( key=='<' || key =='>') && (mParser && !mParser->isIncludeLine(lineText()))) @@ -3080,7 +3080,7 @@ Editor::QuoteStatus Editor::getQuoteStatus() QuoteStatus Result = QuoteStatus::NotQuote; if (!syntaxer()) return Result; - if ((caretY()>1) && syntaxer()->isLastLineStringNotFinished(document()->getSyntaxState(caretY() - 2).state)) + if ((caretY()>1) && syntaxer()->isStringNotFinished(document()->getSyntaxState(caretY() - 2).state)) Result = QuoteStatus::DoubleQuote; QString Line = document()->getLine(caretY()-1); @@ -3470,11 +3470,10 @@ void Editor::showCompletion(const QString& preWord,bool autoComplete, CodeComple QString s; QSynedit::PTokenAttribute attr; - bool tokenFinished; QSynedit::BufferCoord pBeginPos, pEndPos; if (getTokenAttriAtRowCol( QSynedit::BufferCoord{caretX() - 1, - caretY()}, s, tokenFinished, attr)) { + caretY()}, s, attr)) { if (attr->tokenType() == QSynedit::TokenType::Preprocessor) {//Preprocessor word = getWordAtPosition(this,caretXY(),pBeginPos,pEndPos, WordPurpose::wpDirective); if (!word.startsWith('#')) { diff --git a/libs/qsynedit/qsynedit/formatter/cppformatter.cpp b/libs/qsynedit/qsynedit/formatter/cppformatter.cpp index 296c3efa..4336d079 100644 --- a/libs/qsynedit/qsynedit/formatter/cppformatter.cpp +++ b/libs/qsynedit/qsynedit/formatter/cppformatter.cpp @@ -128,7 +128,7 @@ namespace QSynedit { SyntaxState range; while (commentStartLine>=1) { range = editor->document()->getSyntaxState(commentStartLine-1); - if (!editor->syntaxer()->isLastLineCommentNotFinished(range.state)){ + if (!editor->syntaxer()->isCommentNotFinished(range.state)){ commentStartLine++; break; } diff --git a/libs/qsynedit/qsynedit/qsynedit.cpp b/libs/qsynedit/qsynedit/qsynedit.cpp index 22dc4d6a..908c7c4e 100644 --- a/libs/qsynedit/qsynedit/qsynedit.cpp +++ b/libs/qsynedit/qsynedit/qsynedit.cpp @@ -341,7 +341,9 @@ bool QSynEdit::getTokenAttriAtRowCol(const BufferCoord &pos, QString &token, PTo return getTokenAttriAtRowColEx(pos, token, tmpStart, attri); } -bool QSynEdit::getTokenAttriAtRowCol(const BufferCoord &pos, QString &token, bool &tokenFinished, PTokenAttribute &attri) +bool QSynEdit::getTokenAttriAtRowCol( + const BufferCoord &pos, QString &token, + PTokenAttribute &attri, SyntaxState &syntaxState) { int posX, posY, endPos, start; QString line; @@ -362,10 +364,7 @@ bool QSynEdit::getTokenAttriAtRowCol(const BufferCoord &pos, QString &token, boo endPos = start + token.length()-1; if ((posX >= start) && (posX <= endPos)) { attri = mSyntaxer->getTokenAttribute(); - if (posX == endPos) - tokenFinished = mSyntaxer->getTokenFinished(); - else - tokenFinished = false; + syntaxState = mSyntaxer->getState(); return true; } mSyntaxer->next(); @@ -374,7 +373,6 @@ bool QSynEdit::getTokenAttriAtRowCol(const BufferCoord &pos, QString &token, boo } token = ""; attri = PTokenAttribute(); - tokenFinished = false; return false; } @@ -2321,9 +2319,9 @@ void QSynEdit::insertLine(bool moveCaret) mSyntaxer->setLine(leftLineText, mCaretY-1); mSyntaxer->nextToEol(); mDocument->setSyntaxState(mCaretY-1,mSyntaxer->getState()); - notInComment = !mSyntaxer->isLastLineCommentNotFinished( + notInComment = !mSyntaxer->isCommentNotFinished( mSyntaxer->getState().state) - && !mSyntaxer->isLastLineStringNotFinished( + && !mSyntaxer->isStringNotFinished( mSyntaxer->getState().state); } int indentSpaces = 0; @@ -5465,9 +5463,9 @@ int QSynEdit::doInsertTextByNormalMode(const BufferCoord& pos, const QStringList for (int i=1;iisLastLineCommentNotFinished( +// notInComment = !mHighlighter->isCommentNotFinished( // mHighlighter->getRangeState().state) -// && !mHighlighter->isLastLineStringNotFinished( +// && !mHighlighter->isStringNotFinished( // mHighlighter->getRangeState().state); // } caretY=pos.line+i; diff --git a/libs/qsynedit/qsynedit/qsynedit.h b/libs/qsynedit/qsynedit/qsynedit.h index fc17ed03..a9b70e12 100644 --- a/libs/qsynedit/qsynedit/qsynedit.h +++ b/libs/qsynedit/qsynedit/qsynedit.h @@ -264,7 +264,7 @@ public: bool getTokenAttriAtRowCol(const BufferCoord& pos, QString& token, PTokenAttribute& attri); bool getTokenAttriAtRowCol(const BufferCoord& pos, QString& token, - bool& tokenFinished, PTokenAttribute& attri); + PTokenAttribute& attri, SyntaxState &syntaxState); bool getTokenAttriAtRowColEx(const BufferCoord& pos, QString& token, int &start, PTokenAttribute& attri); diff --git a/libs/qsynedit/qsynedit/syntaxer/asm.cpp b/libs/qsynedit/qsynedit/syntaxer/asm.cpp index 0c6723c2..d4b8dda5 100644 --- a/libs/qsynedit/qsynedit/syntaxer/asm.cpp +++ b/libs/qsynedit/qsynedit/syntaxer/asm.cpp @@ -344,7 +344,7 @@ void ASMSyntaxer::UnknownProc() mTokenID = TokenId::Unknown; } -bool ASMSyntaxer::isIdentStartChar(const QChar &ch) +bool ASMSyntaxer::isIdentStartChar(const QChar &ch) const { if (ch == '_') { return true; @@ -1718,17 +1718,12 @@ void ASMSyntaxer::setLine(const QString &newLine, int lineNumber) next(); } -bool ASMSyntaxer::getTokenFinished() const +bool ASMSyntaxer::isCommentNotFinished(int /*state*/) const { return true; } -bool ASMSyntaxer::isLastLineCommentNotFinished(int /*state*/) const -{ - return true; -} - -bool ASMSyntaxer::isLastLineStringNotFinished(int /*state*/) const +bool ASMSyntaxer::isStringNotFinished(int /*state*/) const { return true; } diff --git a/libs/qsynedit/qsynedit/syntaxer/asm.h b/libs/qsynedit/qsynedit/syntaxer/asm.h index f5b73b72..31340321 100644 --- a/libs/qsynedit/qsynedit/syntaxer/asm.h +++ b/libs/qsynedit/qsynedit/syntaxer/asm.h @@ -91,7 +91,7 @@ private: void StringProc(); void SymbolProc(); void UnknownProc(); - bool isIdentStartChar(const QChar& ch); + bool isIdentStartChar(const QChar& ch) const override; static void initData(); // SynHighlighter interface @@ -108,9 +108,8 @@ public: // SynHighlighter interface public: - bool getTokenFinished() const override; - bool isLastLineCommentNotFinished(int state) const override; - bool isLastLineStringNotFinished(int state) const override; + bool isCommentNotFinished(int state) const override; + bool isStringNotFinished(int state) const override; SyntaxState getState() const override; void setState(const SyntaxState& rangeState) override; void resetState() override; diff --git a/libs/qsynedit/qsynedit/syntaxer/cpp.cpp b/libs/qsynedit/qsynedit/syntaxer/cpp.cpp index 06195fe7..67336a63 100644 --- a/libs/qsynedit/qsynedit/syntaxer/cpp.cpp +++ b/libs/qsynedit/qsynedit/syntaxer/cpp.cpp @@ -1505,17 +1505,7 @@ QString CppSyntaxer::blockCommentEndSymbol() return "*/"; } -bool CppSyntaxer::getTokenFinished() const -{ - if (mTokenId == TokenId::Comment - || mTokenId == TokenId::String - || mTokenId == TokenId::RawString) { - return mRange.state == RangeState::rsUnknown; - } - return true; -} - -bool CppSyntaxer::isLastLineCommentNotFinished(int state) const +bool CppSyntaxer::isCommentNotFinished(int state) const { return (state == RangeState::rsAnsiC || state == RangeState::rsDirectiveComment|| @@ -1523,7 +1513,7 @@ bool CppSyntaxer::isLastLineCommentNotFinished(int state) const state == RangeState::rsCppComment); } -bool CppSyntaxer::isLastLineStringNotFinished(int state) const +bool CppSyntaxer::isStringNotFinished(int state) const { return state == RangeState::rsString; } diff --git a/libs/qsynedit/qsynedit/syntaxer/cpp.h b/libs/qsynedit/qsynedit/syntaxer/cpp.h index 2c7509ad..ff3620dd 100644 --- a/libs/qsynedit/qsynedit/syntaxer/cpp.h +++ b/libs/qsynedit/qsynedit/syntaxer/cpp.h @@ -177,9 +177,8 @@ private: // SynHighligterBase interface public: - bool getTokenFinished() const override; - bool isLastLineCommentNotFinished(int state) const override; - bool isLastLineStringNotFinished(int state) const override; + bool isCommentNotFinished(int state) const override; + bool isStringNotFinished(int state) const override; bool isDocstringNotFinished(int state) const override; bool eol() const override; QString getToken() const override; diff --git a/libs/qsynedit/qsynedit/syntaxer/glsl.cpp b/libs/qsynedit/qsynedit/syntaxer/glsl.cpp index a020f53e..65a460f8 100644 --- a/libs/qsynedit/qsynedit/syntaxer/glsl.cpp +++ b/libs/qsynedit/qsynedit/syntaxer/glsl.cpp @@ -1236,24 +1236,14 @@ void GLSLSyntaxer::pushIndents(IndentType indentType, int line) mRange.indents.push_back(IndentInfo{indentType,line}); } -bool GLSLSyntaxer::getTokenFinished() const -{ - if (mTokenId == TokenId::Comment - || mTokenId == TokenId::String - || mTokenId == TokenId::RawString) { - return mRange.state == RangeState::rsUnknown; - } - return true; -} - -bool GLSLSyntaxer::isLastLineCommentNotFinished(int state) const +bool GLSLSyntaxer::isCommentNotFinished(int state) const { return (state == RangeState::rsAnsiC || state == RangeState::rsDirectiveComment|| state == RangeState::rsCppComment); } -bool GLSLSyntaxer::isLastLineStringNotFinished(int state) const +bool GLSLSyntaxer::isStringNotFinished(int state) const { return state == RangeState::rsMultiLineString; } diff --git a/libs/qsynedit/qsynedit/syntaxer/glsl.h b/libs/qsynedit/qsynedit/syntaxer/glsl.h index 1caf9f2f..66e7f4a5 100644 --- a/libs/qsynedit/qsynedit/syntaxer/glsl.h +++ b/libs/qsynedit/qsynedit/syntaxer/glsl.h @@ -161,9 +161,8 @@ private: // SynHighligterBase interface public: - bool getTokenFinished() const override; - bool isLastLineCommentNotFinished(int state) const override; - bool isLastLineStringNotFinished(int state) const override; + bool isCommentNotFinished(int state) const override; + bool isStringNotFinished(int state) const override; bool eol() const override; QString getToken() const override; const PTokenAttribute &getTokenAttribute() const override; diff --git a/libs/qsynedit/qsynedit/syntaxer/lua.cpp b/libs/qsynedit/qsynedit/syntaxer/lua.cpp index 288af9a2..ccbf2d61 100644 --- a/libs/qsynedit/qsynedit/syntaxer/lua.cpp +++ b/libs/qsynedit/qsynedit/syntaxer/lua.cpp @@ -1005,22 +1005,13 @@ QMap > LuaSyntaxer::scopedKeywords() return StdLibTables; } -bool LuaSyntaxer::getTokenFinished() const -{ - if (mTokenId == TokenId::Comment - || mTokenId == TokenId::String) { - return mRange.state == RangeState::rsUnknown; - } - return true; -} - -bool LuaSyntaxer::isLastLineCommentNotFinished(int state) const +bool LuaSyntaxer::isCommentNotFinished(int state) const { return (state == RangeState::rsComment || state == RangeState::rsLongComment); } -bool LuaSyntaxer::isLastLineStringNotFinished(int state) const +bool LuaSyntaxer::isStringNotFinished(int state) const { return state == RangeState::rsString; } diff --git a/libs/qsynedit/qsynedit/syntaxer/lua.h b/libs/qsynedit/qsynedit/syntaxer/lua.h index d031a70e..fa01621e 100644 --- a/libs/qsynedit/qsynedit/syntaxer/lua.h +++ b/libs/qsynedit/qsynedit/syntaxer/lua.h @@ -140,9 +140,8 @@ private: // SynHighligterBase interface public: - bool getTokenFinished() const override; - bool isLastLineCommentNotFinished(int state) const override; - bool isLastLineStringNotFinished(int state) const override; + bool isCommentNotFinished(int state) const override; + bool isStringNotFinished(int state) const override; bool eol() const override; QString getToken() const override; const PTokenAttribute &getTokenAttribute() const override; diff --git a/libs/qsynedit/qsynedit/syntaxer/makefile.cpp b/libs/qsynedit/qsynedit/syntaxer/makefile.cpp index f74ac3d8..476f12f4 100644 --- a/libs/qsynedit/qsynedit/syntaxer/makefile.cpp +++ b/libs/qsynedit/qsynedit/syntaxer/makefile.cpp @@ -649,17 +649,12 @@ void MakefileSyntaxer::setLine(const QString &newLine, int lineNumber) next(); } -bool MakefileSyntaxer::getTokenFinished() const -{ - return true; -} - -bool MakefileSyntaxer::isLastLineCommentNotFinished(int /*state*/) const +bool MakefileSyntaxer::isCommentNotFinished(int /*state*/) const { return false; } -bool MakefileSyntaxer::isLastLineStringNotFinished(int /*state*/) const +bool MakefileSyntaxer::isStringNotFinished(int /*state*/) const { return false; } diff --git a/libs/qsynedit/qsynedit/syntaxer/makefile.h b/libs/qsynedit/qsynedit/syntaxer/makefile.h index 1a6c00eb..cfbf797e 100644 --- a/libs/qsynedit/qsynedit/syntaxer/makefile.h +++ b/libs/qsynedit/qsynedit/syntaxer/makefile.h @@ -108,7 +108,7 @@ private: void pushState(); void popState(); - bool isIdentStartChar(const QChar& ch) { + bool isIdentStartChar(const QChar& ch) const override{ if ((ch>='a') && (ch <= 'z')) { return true; } @@ -145,9 +145,8 @@ public: // SynHighlighter interface public: - bool getTokenFinished() const override; - bool isLastLineCommentNotFinished(int state) const override; - bool isLastLineStringNotFinished(int state) const override; + bool isCommentNotFinished(int state) const override; + bool isStringNotFinished(int state) const override; SyntaxState getState() const override; void setState(const SyntaxState& rangeState) override; void resetState() override; diff --git a/libs/qsynedit/qsynedit/syntaxer/syntaxer.h b/libs/qsynedit/qsynedit/syntaxer/syntaxer.h index 96a708a2..203ea449 100644 --- a/libs/qsynedit/qsynedit/syntaxer/syntaxer.h +++ b/libs/qsynedit/qsynedit/syntaxer/syntaxer.h @@ -141,9 +141,8 @@ public: virtual bool isIdentChar(const QChar& ch) const; virtual bool isIdentStartChar(const QChar& ch) const; - virtual bool getTokenFinished() const = 0; - virtual bool isLastLineCommentNotFinished(int state) const = 0; - virtual bool isLastLineStringNotFinished(int state) const = 0; + virtual bool isCommentNotFinished(int state) const = 0; + virtual bool isStringNotFinished(int state) const = 0; virtual bool isDocstringNotFinished(int /* state */) const { return false; } virtual bool eol() const = 0; virtual SyntaxState getState() const = 0;