- fix: Slow when paste/replace bulk contents.

This commit is contained in:
Roy Qu 2024-09-12 11:01:36 +08:00
parent fdaf7d3a49
commit 63965f6eab
4 changed files with 20 additions and 10 deletions

View File

@ -5,6 +5,7 @@ Red Panda C++ Version 3.2
- fix: Don't auto scroll to the caret after undo/redo. - fix: Don't auto scroll to the caret after undo/redo.
- fix: "bits/stdc++" is not openned in readonly mode. - fix: "bits/stdc++" is not openned in readonly mode.
- fix: astyle path error when reformat. - fix: astyle path error when reformat.
- fix: Slow when paste/replace bulk contents.
Red Panda C++ Version 3.1 Red Panda C++ Version 3.1

View File

@ -452,6 +452,7 @@ void Document::putLine(int index, const QString &s, bool notify) {
if (index<0 || index>=mLines.count()) { if (index<0 || index>=mLines.count()) {
listIndexOutOfBounds(index); listIndexOutOfBounds(index);
} }
if (notify)
beginUpdate(); beginUpdate();
mLines[index]->setLineText(s); mLines[index]->setLineText(s);
if (mIndexOfLongestLine == index) { if (mIndexOfLongestLine == index) {
@ -460,6 +461,7 @@ void Document::putLine(int index, const QString &s, bool notify) {
} }
if (notify) if (notify)
emit putted(index); emit putted(index);
if (notify)
endUpdate(); endUpdate();
} }
} }

View File

@ -3246,12 +3246,15 @@ void QSynEdit::updateModifiedStatus()
emit statusChanged(StatusChange::ModifyChanged); emit statusChanged(StatusChange::ModifyChanged);
} }
int QSynEdit::reparseLines(int startLine, int endLine) int QSynEdit::reparseLines(int startLine, int endLine, bool needRescanFolds, bool toDocumentEnd)
{ {
SyntaxState state; SyntaxState state;
int maxLine = toDocumentEnd ? mDocument->count() : endLine+1;
startLine = std::max(0,startLine); startLine = std::max(0,startLine);
endLine = std::min(endLine, mDocument->count()); endLine = std::min(endLine, mDocument->count());
maxLine = std::min(maxLine, mDocument->count());
if (startLine >= endLine) if (startLine >= endLine)
return startLine; return startLine;
@ -3271,7 +3274,7 @@ int QSynEdit::reparseLines(int startLine, int endLine)
} }
mDocument->setSyntaxState(line,state); mDocument->setSyntaxState(line,state);
line++; line++;
} while (line < mDocument->count()); } while (line < maxLine);
//don't rescan folds if only currentLine is reparsed //don't rescan folds if only currentLine is reparsed
if (line-startLine==1) if (line-startLine==1)
@ -3280,7 +3283,7 @@ int QSynEdit::reparseLines(int startLine, int endLine)
if (mEditingCount>0) if (mEditingCount>0)
return line; return line;
if (useCodeFolding()) if (needRescanFolds && useCodeFolding())
rescanFolds(); rescanFolds();
return line; return line;
} }
@ -5359,6 +5362,7 @@ int QSynEdit::doInsertTextByNormalMode(const BufferCoord& pos, const QStringList
QString sLeftSide; QString sLeftSide;
QString sRightSide; QString sRightSide;
QString str; QString str;
QElapsedTimer timer;
bool bChangeScroll; bool bChangeScroll;
// int SpaceCount; // int SpaceCount;
int result = 0; int result = 0;
@ -5382,13 +5386,14 @@ int QSynEdit::doInsertTextByNormalMode(const BufferCoord& pos, const QStringList
str = sLeftSide + s; str = sLeftSide + s;
} else } else
str = sLeftSide + text[0]; str = sLeftSide + text[0];
properSetLine(caretY - 1, str); properSetLine(caretY - 1, str, false);
mDocument->insertLines(caretY, text.length()-1); mDocument->insertLines(caretY, text.length()-1);
} else { } else {
str = sLeftSide + text[0] + sRightSide; str = sLeftSide + text[0] + sRightSide;
properSetLine(caretY - 1, str); properSetLine(caretY - 1, str, false);
} }
reparseLines(caretY-1,caretY); reparseLines(caretY-1,caretY, false, false);
timer.start();
// step2: insert remaining lines of Value // step2: insert remaining lines of Value
for (int i=1;i<text.length();i++) { for (int i=1;i<text.length();i++) {
bool notInComment = true; bool notInComment = true;
@ -5409,9 +5414,11 @@ int QSynEdit::doInsertTextByNormalMode(const BufferCoord& pos, const QStringList
str = GetLeftSpacing(indentSpaces,true)+trimLeft(str); str = GetLeftSpacing(indentSpaces,true)+trimLeft(str);
} }
properSetLine(caretY - 1, str,false); properSetLine(caretY - 1, str,false);
reparseLines(caretY-1,caretY); reparseLines(caretY-1,caretY, false, false);
result++; result++;
} }
if (useCodeFolding())
rescanFolds();
bChangeScroll = !mOptions.testFlag(EditorOption::ScrollPastEol); bChangeScroll = !mOptions.testFlag(EditorOption::ScrollPastEol);
mOptions.setFlag(EditorOption::ScrollPastEol); mOptions.setFlag(EditorOption::ScrollPastEol);
auto action = finally([&,this]{ auto action = finally([&,this]{

View File

@ -528,7 +528,7 @@ private:
void updateCaret(); void updateCaret();
void recalcCharExtent(); void recalcCharExtent();
void updateModifiedStatus(); void updateModifiedStatus();
int reparseLines(int startLine, int endLine); int reparseLines(int startLine, int endLine, bool needRescanFolds = true, bool toDocumentEnd = true);
//void reparseLine(int line); //void reparseLine(int line);
void uncollapse(PCodeFoldingRange FoldRange); void uncollapse(PCodeFoldingRange FoldRange);
void collapse(PCodeFoldingRange FoldRange); void collapse(PCodeFoldingRange FoldRange);