fix: folding range calculation error when open file

This commit is contained in:
Roy Qu 2023-02-08 10:23:34 +08:00
parent 5d3a933932
commit aac17beb85
3 changed files with 12 additions and 2 deletions

View File

@ -1606,10 +1606,10 @@ int QSynEdit::calcIndentSpaces(int line, const QString& lineText, bool addIndent
if (mSyntaxer->language() != ProgrammingLanguage::CPP)
return indentSpaces;
SyntaxState rangePreceeding = mDocument->getSyntaxState(startLine-1);
mSyntaxer->setState(rangePreceeding);
if (addIndent) {
// QString trimmedS = s.trimmed();
QString trimmedLineText = lineText.trimmed();
mSyntaxer->setState(rangePreceeding);
mSyntaxer->setLine(trimmedLineText,line-1);
int statePrePre;
if (startLine>1) {
@ -3336,7 +3336,7 @@ int QSynEdit::scanFrom(int Index, int canStopIndex)
mSyntaxer->nextToEol();
iRange = mSyntaxer->getState();
if (Result > canStopIndex){
if (mDocument->getSyntaxState(Result).state == iRange.state
if (mDocument->getSyntaxState(Result) == iRange
&& mDocument->getSyntaxState(Result).blockLevel == iRange.blockLevel
&& mDocument->getSyntaxState(Result).blockStarted == iRange.blockStarted
&& mDocument->getSyntaxState(Result).blockEnded == iRange.blockEnded

View File

@ -1571,6 +1571,11 @@ void CppSyntaxer::setLine(const QString &newLine, int lineNumber)
mLineSize = mLine.size();
mLineNumber = lineNumber;
mRun = 0;
mRange.blockStarted = 0;
mRange.blockEnded = 0;
mRange.blockEndedLastLine = 0;
mRange.lastUnindent=IndentInfo{IndentType::None,0};
mRange.hasTrailingSpaces = false;
next();
}

View File

@ -1383,6 +1383,11 @@ void GLSLSyntaxer::setLine(const QString &newLine, int lineNumber)
mLine = mLineString.data();
mLineNumber = lineNumber;
mRun = 0;
mRange.blockStarted = 0;
mRange.blockEnded = 0;
mRange.blockEndedLastLine = 0;
mRange.lastUnindent=IndentInfo{IndentType::None,0};
mRange.hasTrailingSpaces = false;
next();
}