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

View File

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

View File

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