- fix: After spaces in comments and strings, symbol completion for '{' and '(' are wrong.
This commit is contained in:
parent
25453e28eb
commit
cb66c7f340
1
NEWS.md
1
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.
|
||||
|
|
|
@ -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('#')) {
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
|
|
@ -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;i<text.length();i++) {
|
||||
bool notInComment = true;
|
||||
// if (mHighlighter) {
|
||||
// notInComment = !mHighlighter->isLastLineCommentNotFinished(
|
||||
// notInComment = !mHighlighter->isCommentNotFinished(
|
||||
// mHighlighter->getRangeState().state)
|
||||
// && !mHighlighter->isLastLineStringNotFinished(
|
||||
// && !mHighlighter->isStringNotFinished(
|
||||
// mHighlighter->getRangeState().state);
|
||||
// }
|
||||
caretY=pos.line+i;
|
||||
|
|
|
@ -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);
|
||||
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -1005,22 +1005,13 @@ QMap<QString, QSet<QString> > 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;
|
||||
}
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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;
|
||||
|
|
Loading…
Reference in New Issue