From 30e7751abfe68144de1833bf935c3d5788e9a9fb Mon Sep 17 00:00:00 2001 From: Roy Qu Date: Tue, 7 May 2024 16:20:47 +0800 Subject: [PATCH] optimize editing --- libs/qsynedit/qsynedit/qsynedit.cpp | 21 +++++++++++--------- libs/qsynedit/qsynedit/qsynedit.h | 2 +- libs/qsynedit/qsynedit/syntaxer/syntaxer.cpp | 1 + 3 files changed, 14 insertions(+), 10 deletions(-) diff --git a/libs/qsynedit/qsynedit/qsynedit.cpp b/libs/qsynedit/qsynedit/qsynedit.cpp index 81faf289..278de51b 100644 --- a/libs/qsynedit/qsynedit/qsynedit.cpp +++ b/libs/qsynedit/qsynedit/qsynedit.cpp @@ -3268,7 +3268,7 @@ void QSynEdit::updateModifiedStatus() emit statusChanged(StatusChange::ModifyChanged); } -void QSynEdit::reparseLines(int startLine, int endLine) +int QSynEdit::reparseLines(int startLine, int endLine) { SyntaxState state; @@ -3276,7 +3276,7 @@ void QSynEdit::reparseLines(int startLine, int endLine) endLine = std::min(endLine, mDocument->count()); if (startLine >= endLine) - return; + return startLine; if (startLine == 0) { mSyntaxer->resetState(); @@ -3288,15 +3288,18 @@ void QSynEdit::reparseLines(int startLine, int endLine) mSyntaxer->setLine(mDocument->getLine(line), line); mSyntaxer->nextToEol(); state = mSyntaxer->getState(); + if (line >= endLine && state == mDocument->getSyntaxState(line)) { + break; + } mDocument->setSyntaxState(line,state); - line++ ; + line++; } while (line < endLine); if (mEditingCount>0) - return; + return line; if (useCodeFolding()) rescanFolds(); - return ; + return line; } // void QSynEdit::reparseLine(int line) @@ -6537,7 +6540,7 @@ void QSynEdit::onLinesDeleted(int line, int count) if (useCodeFolding()) foldOnLinesDeleted(line + 1, count); if (mSyntaxer->needsLineState()) { - reparseLines(line, mDocument->count()); + reparseLines(line, line + 1); } invalidateLines(line + 1, INT_MAX); } @@ -6547,7 +6550,7 @@ void QSynEdit::onLinesInserted(int line, int count) if (useCodeFolding()) foldOnLinesInserted(line + 1, count); if (mSyntaxer->needsLineState()) { - reparseLines(line, mDocument->count()); + reparseLines(line, line + count); } else { // new lines should be parsed reparseLines(line, line + count); @@ -6558,10 +6561,10 @@ void QSynEdit::onLinesInserted(int line, int count) void QSynEdit::onLinesPutted(int line) { if (mSyntaxer->needsLineState()) { - reparseLines(line, mDocument->count()); + reparseLines(line, line + 1); invalidateLines(line + 1, INT_MAX); } else { - reparseLines(line, line+1); + reparseLines(line, line + 1); invalidateLine( line + 1 ); } } diff --git a/libs/qsynedit/qsynedit/qsynedit.h b/libs/qsynedit/qsynedit/qsynedit.h index 34627d7b..d27ecc44 100644 --- a/libs/qsynedit/qsynedit/qsynedit.h +++ b/libs/qsynedit/qsynedit/qsynedit.h @@ -529,7 +529,7 @@ private: void recalcCharExtent(); QString expandAtWideGlyphs(const QString& S); void updateModifiedStatus(); - void reparseLines(int startLine, int endLine); + int reparseLines(int startLine, int endLine); //void reparseLine(int line); void uncollapse(PCodeFoldingRange FoldRange); void collapse(PCodeFoldingRange FoldRange); diff --git a/libs/qsynedit/qsynedit/syntaxer/syntaxer.cpp b/libs/qsynedit/qsynedit/syntaxer/syntaxer.cpp index 58a6e877..5a44a461 100644 --- a/libs/qsynedit/qsynedit/syntaxer/syntaxer.cpp +++ b/libs/qsynedit/qsynedit/syntaxer/syntaxer.cpp @@ -169,6 +169,7 @@ bool SyntaxState::operator==(const SyntaxState &s2) && (parenthesisLevel == s2.parenthesisLevel) // current parenthesis embedding level (needed by rainbow color) && (indents == s2.indents) && (lastUnindent == s2.lastUnindent) + && (extraData == s2.extraData) ; }