- 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: "bits/stdc++" is not openned in readonly mode.
- fix: astyle path error when reformat.
- fix: Slow when paste/replace bulk contents.
Red Panda C++ Version 3.1

View File

@ -452,7 +452,8 @@ void Document::putLine(int index, const QString &s, bool notify) {
if (index<0 || index>=mLines.count()) {
listIndexOutOfBounds(index);
}
beginUpdate();
if (notify)
beginUpdate();
mLines[index]->setLineText(s);
if (mIndexOfLongestLine == index) {
// width is invalidated, so we must recalculate longest line
@ -460,7 +461,8 @@ void Document::putLine(int index, const QString &s, bool notify) {
}
if (notify)
emit putted(index);
endUpdate();
if (notify)
endUpdate();
}
}

View File

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

View File

@ -528,7 +528,7 @@ private:
void updateCaret();
void recalcCharExtent();
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 uncollapse(PCodeFoldingRange FoldRange);
void collapse(PCodeFoldingRange FoldRange);