From a91dc12519faa84ebf1287e240418488dbfc138d Mon Sep 17 00:00:00 2001 From: Roy Qu Date: Sat, 18 Feb 2023 07:09:19 +0800 Subject: [PATCH] - enhancement: Reduce flicker when editing big files. --- NEWS.md | 1 + RedPandaIDE/editor.cpp | 30 ++++++++++++++++++++--------- RedPandaIDE/editor.h | 2 ++ libs/qsynedit/qsynedit/document.cpp | 6 +++--- 4 files changed, 27 insertions(+), 12 deletions(-) diff --git a/NEWS.md b/NEWS.md index 2451000e..2ef119ff 100644 --- a/NEWS.md +++ b/NEWS.md @@ -37,6 +37,7 @@ Red Panda C++ Version 2.12 - enhancement: Show "..." instead of "...}" when folding #if/#endif - enhancement: Correctly handle high-precision mouse wheel / touchpad in editors. - enhancement: Greatly reduce time to open/edit big files. + - enhancement: Reduce flicker when editing big files. Red Panda C++ Version 2.11 diff --git a/RedPandaIDE/editor.cpp b/RedPandaIDE/editor.cpp index 3ad109e3..1b3db7e5 100644 --- a/RedPandaIDE/editor.cpp +++ b/RedPandaIDE/editor.cpp @@ -1125,12 +1125,18 @@ void Editor::onPreparePaintHighlightToken(int line, int aChar, const QString &to // qDebug()<findStatementOf(mFilename, // s , p.Line); - QStringList expression = getExpressionAtPosition(p); - PStatement statement = parser()->findStatementOf( - filename(), - expression, - p.line); - StatementKind kind = getKindOfStatement(statement); + StatementKind kind; + if (mParser->parsing()){ + kind=mIdentCache.value(QString("%1 %2").arg(aChar).arg(token),StatementKind::skUnknown); + } else { + QStringList expression = getExpressionAtPosition(p); + PStatement statement = parser()->findStatementOf( + filename(), + expression, + p.line); + kind = getKindOfStatement(statement); + mIdentCache.insert(QString("%1 %2").arg(aChar).arg(token),kind); + } if (kind == StatementKind::skUnknown) { QSynedit::BufferCoord pBeginPos,pEndPos; QString s= getWordAtPosition(this,p, pBeginPos,pEndPos, WordPurpose::wpInformation); @@ -1356,7 +1362,7 @@ void Editor::showEvent(QShowEvent */*event*/) connect(mParser.get(), &CppParser::onEndParsing, this, - &QSynedit::QSynEdit::invalidate); + &Editor::onEndParsing); reparse(false); } if (mParentPageControl) { @@ -1399,7 +1405,7 @@ void Editor::hideEvent(QHideEvent */*event*/) disconnect(mParser.get(), &CppParser::onEndParsing, this, - &QSynedit::QSynEdit::invalidate); + &Editor::onEndParsing); } pMainWindow->updateForEncodingInfo(nullptr); pMainWindow->updateStatusbarForLineCol(nullptr); @@ -1973,6 +1979,12 @@ void Editor::onTooltipTimer() } } +void Editor::onEndParsing() +{ + mIdentCache.clear(); + invalidate(); +} + void Editor::resolveAutoDetectEncodingOption() { if (mEncodingOption==ENCODING_AUTO_DETECT) { @@ -4341,7 +4353,7 @@ void Editor::setProject(Project *pProject) connect(mParser.get(), &CppParser::onEndParsing, this, - &QSynedit::QSynEdit::invalidate); + &Editor::onEndParsing); } else { invalidate(); } diff --git a/RedPandaIDE/editor.h b/RedPandaIDE/editor.h index d416ebc6..c6501174 100644 --- a/RedPandaIDE/editor.h +++ b/RedPandaIDE/editor.h @@ -237,6 +237,7 @@ private slots: void onFunctionTipsTimer(); void onAutoBackupTimer(); void onTooltipTimer(); + void onEndParsing(); private: void resolveAutoDetectEncodingOption(); @@ -348,6 +349,7 @@ private: QTimer mTooltipTimer; int mHoverModifiedLine; int mWheelAccumulatedDelta; + QMap mIdentCache; static QHash> mSharedParsers; diff --git a/libs/qsynedit/qsynedit/document.cpp b/libs/qsynedit/qsynedit/document.cpp index bfb65e7b..cddc8553 100644 --- a/libs/qsynedit/qsynedit/document.cpp +++ b/libs/qsynedit/qsynedit/document.cpp @@ -260,12 +260,12 @@ void Document::setContents(const QStringList &text) QStringList Document::contents() { QMutexLocker locker(&mMutex); - QStringList Result; + QStringList result; DocumentLines list = mLines; foreach (const PDocumentLine& line, list) { - Result.append(line->lineText); + result.append(line->lineText); } - return Result; + return result; } void Document::beginUpdate()