- enhancement: Internal optimization for open/edit files.

This commit is contained in:
Roy Qu 2024-03-05 16:34:41 +08:00
parent bbe79297ef
commit e0438b1bf9
5 changed files with 54 additions and 24 deletions

View File

@ -31,6 +31,7 @@ Red Panda C++ Version 2.27
- fix: "float" in #include "float.h" is wrong syntax colored. - fix: "float" in #include "float.h" is wrong syntax colored.
- enhancement: Unify syntax color for #include header name - enhancement: Unify syntax color for #include header name
- enhancement: Issue #229 Press Enter/Return in the tree view in files panel will open the file. - enhancement: Issue #229 Press Enter/Return in the tree view in files panel will open the file.
- enhancement: Internal optimization for open/edit files.
Red Panda C++ Version 2.26 Red Panda C++ Version 2.26
- enhancement: Code suggestion for embedded std::vectors. - enhancement: Code suggestion for embedded std::vectors.

View File

@ -5298,6 +5298,7 @@ void Editor::setActiveBreakpointFocus(int Line, bool setFocus)
void Editor::applySettings() void Editor::applySettings()
{ {
incPaintLock();
QSynedit::EditorOptions options = QSynedit::eoAltSetsColumnMode | QSynedit::EditorOptions options = QSynedit::eoAltSetsColumnMode |
QSynedit::eoDragDropEditing | QSynedit::eoDropFiles | QSynedit::eoKeepCaretX | QSynedit::eoTabsToSpaces | QSynedit::eoDragDropEditing | QSynedit::eoDropFiles | QSynedit::eoKeepCaretX | QSynedit::eoTabsToSpaces |
QSynedit::eoRightMouseMovesCursor | QSynedit::eoScrollByOneLess | QSynedit::eoTabIndent | QSynedit::eoHideShowScrollbars | QSynedit::eoGroupUndo QSynedit::eoRightMouseMovesCursor | QSynedit::eoScrollByOneLess | QSynedit::eoTabIndent | QSynedit::eoHideShowScrollbars | QSynedit::eoGroupUndo
@ -5414,6 +5415,7 @@ void Editor::applySettings()
setMouseWheelScrollSpeed(pSettings->editor().mouseWheelScrollSpeed()); setMouseWheelScrollSpeed(pSettings->editor().mouseWheelScrollSpeed());
setMouseSelectionScrollSpeed(pSettings->editor().mouseSelectionScrollSpeed()); setMouseSelectionScrollSpeed(pSettings->editor().mouseSelectionScrollSpeed());
invalidate(); invalidate();
decPaintLock();
} }
static QSynedit::PTokenAttribute createRainbowAttribute(const QString& attrName, const QString& schemeName, const QString& schemeItemName) { static QSynedit::PTokenAttribute createRainbowAttribute(const QString& attrName, const QString& schemeName, const QString& schemeItemName) {

View File

@ -146,7 +146,10 @@ int Document::longestLineWidth() {
mIndexOfLongestLine = -1; mIndexOfLongestLine = -1;
if (mLines.count() > 0 ) { if (mLines.count() > 0 ) {
for (int i=0;i<mLines.size();i++) { for (int i=0;i<mLines.size();i++) {
int len = lineWidth(i); int len = mLines[i]->width();
//Just estimate it.
if (len<0)
len = mCharWidth * mLines[i]->lineText().length();
if (len > MaxLen) { if (len > MaxLen) {
MaxLen = len; MaxLen = len;
mIndexOfLongestLine = i; mIndexOfLongestLine = i;

View File

@ -634,7 +634,12 @@ bool QSynEdit::pointToLine(const QPoint &point, int &line)
void QSynEdit::invalidateGutter() void QSynEdit::invalidateGutter()
{ {
invalidateGutterLines(-1, -1); if (mPaintLock>0) {
mStateFlags.setFlag(StateFlag::sfGutterRedrawNeeded);
} else {
mStateFlags.setFlag(StateFlag::sfGutterRedrawNeeded, false);
invalidateGutterLines(-1, -1);
}
} }
void QSynEdit::invalidateGutterLine(int aLine) void QSynEdit::invalidateGutterLine(int aLine)
@ -1050,10 +1055,12 @@ void QSynEdit::invalidateRect(const QRect &rect)
void QSynEdit::invalidate() void QSynEdit::invalidate()
{ {
if (mPainterLock>0) if (mPainterLock>0) {
return; mStateFlags.setFlag(StateFlag::sfRedrawNeeded);
// qDebug()<<"invalidate"; } else {
viewport()->update(); mStateFlags.setFlag(StateFlag::sfRedrawNeeded, false);
viewport()->update();
}
} }
void QSynEdit::lockPainter() void QSynEdit::lockPainter()
@ -2968,6 +2975,10 @@ void QSynEdit::decPaintLock()
} }
if (mStateFlags.testFlag(StateFlag::sfCaretChanged)) if (mStateFlags.testFlag(StateFlag::sfCaretChanged))
updateCaret(); updateCaret();
if (mStateFlags.testFlag(StateFlag::sfGutterRedrawNeeded))
invalidateGutter();
if (mStateFlags.testFlag(StateFlag::sfRedrawNeeded))
invalidate();
if (mStatusChanges!=0) if (mStatusChanges!=0)
doOnStatusChange(mStatusChanges); doOnStatusChange(mStatusChanges);
onEndFirstPaintLock(); onEndFirstPaintLock();
@ -3001,8 +3012,10 @@ QRect QSynEdit::clientRect() const
void QSynEdit::synFontChanged() void QSynEdit::synFontChanged()
{ {
incPaintLock();
recalcCharExtent(); recalcCharExtent();
onSizeOrFontChanged(true); onSizeOrFontChanged(true);
decPaintLock();
} }
@ -3799,8 +3812,12 @@ void QSynEdit::setLineSpacingFactor(double newLineSpacingFactor)
{ {
if (newLineSpacingFactor<1.0) if (newLineSpacingFactor<1.0)
newLineSpacingFactor = 1.0; newLineSpacingFactor = 1.0;
mLineSpacingFactor = newLineSpacingFactor; if (mLineSpacingFactor != newLineSpacingFactor) {
recalcCharExtent(); incPaintLock();
mLineSpacingFactor = newLineSpacingFactor;
recalcCharExtent();
decPaintLock();
}
} }
ScrollStyle QSynEdit::scrollBars() const ScrollStyle QSynEdit::scrollBars() const
@ -3912,8 +3929,10 @@ int QSynEdit::rightEdge() const
void QSynEdit::setRightEdge(int newRightEdge) void QSynEdit::setRightEdge(int newRightEdge)
{ {
if (mRightEdge != newRightEdge) { if (mRightEdge != newRightEdge) {
incPaintLock();
mRightEdge = newRightEdge; mRightEdge = newRightEdge;
invalidate(); invalidate();
decPaintLock();
} }
} }
@ -4006,8 +4025,10 @@ void QSynEdit::setCaretColor(const QColor &caretColor)
void QSynEdit::setTabSize(int newTabSize) void QSynEdit::setTabSize(int newTabSize)
{ {
if (newTabSize!=tabSize()) { if (newTabSize!=tabSize()) {
incPaintLock();
mDocument->setTabSize(newTabSize); mDocument->setTabSize(newTabSize);
invalidate(); invalidate();
decPaintLock();
} }
} }
@ -4023,6 +4044,7 @@ static bool sameEditorOption(const EditorOptions& value1, const EditorOptions& v
void QSynEdit::setOptions(const EditorOptions &Value) void QSynEdit::setOptions(const EditorOptions &Value)
{ {
if (Value != mOptions) { if (Value != mOptions) {
incPaintLock();
//bool bSetDrag = mOptions.testFlag(eoDropFiles) != Value.testFlag(eoDropFiles); //bool bSetDrag = mOptions.testFlag(eoDropFiles) != Value.testFlag(eoDropFiles);
//if (!mOptions.testFlag(eoScrollPastEol)) //if (!mOptions.testFlag(eoScrollPastEol))
setLeftPos(mLeftPos); setLeftPos(mLeftPos);
@ -4037,8 +4059,6 @@ void QSynEdit::setOptions(const EditorOptions &Value)
|| !sameEditorOption(Value,mOptions, eoShowTrailingSpaces) || !sameEditorOption(Value,mOptions, eoShowTrailingSpaces)
|| !sameEditorOption(Value,mOptions, eoShowLineBreaks) || !sameEditorOption(Value,mOptions, eoShowLineBreaks)
|| !sameEditorOption(Value,mOptions, eoShowRainbowColor); || !sameEditorOption(Value,mOptions, eoShowRainbowColor);
//bool bUpdateScroll = (Options * ScrollOptions)<>(Value * ScrollOptions);
bool bUpdateScroll = true;
mOptions = Value; mOptions = Value;
mDocument->setForceMonospace(mOptions.testFlag(eoForceMonospace) ); mDocument->setForceMonospace(mOptions.testFlag(eoForceMonospace) );
@ -4052,13 +4072,9 @@ void QSynEdit::setOptions(const EditorOptions &Value)
setBlockEnd(vTempBlockEnd); setBlockEnd(vTempBlockEnd);
} }
updateScrollbars(); updateScrollbars();
// (un)register HWND as drop target
// if bSetDrag and not (csDesigning in ComponentState) and HandleAllocated then
// DragAcceptFiles(Handle, (eoDropFiles in fOptions));
if (bUpdateAll) if (bUpdateAll)
invalidate(); invalidate();
if (bUpdateScroll) decPaintLock();
updateScrollbars();
} }
} }
@ -6889,6 +6905,7 @@ void QSynEdit::setTopLine(int Value)
void QSynEdit::onGutterChanged() void QSynEdit::onGutterChanged()
{ {
incPaintLock();
if (mGutter.showLineNumbers() && mGutter.autoSize()) if (mGutter.showLineNumbers() && mGutter.autoSize())
mGutter.autoSizeDigitCount(mDocument->count()); mGutter.autoSizeDigitCount(mDocument->count());
int nW; int nW;
@ -6902,6 +6919,7 @@ void QSynEdit::onGutterChanged()
invalidateGutter(); invalidateGutter();
else else
setGutterWidth(nW); setGutterWidth(nW);
decPaintLock();
} }
void QSynEdit::onScrollTimeout() void QSynEdit::onScrollTimeout()

View File

@ -61,13 +61,15 @@ Q_DECLARE_FLAGS(StatusChanges, StatusChange)
Q_DECLARE_OPERATORS_FOR_FLAGS(StatusChanges) Q_DECLARE_OPERATORS_FOR_FLAGS(StatusChanges)
enum class StateFlag { enum class StateFlag {
sfCaretChanged = 0x0001, sfCaretChanged = 0x0001,
sfScrollbarChanged = 0x0002, sfScrollbarChanged = 0x0002,
sfLinesChanging = 0x0004, sfLinesChanging = 0x0004,
sfIgnoreNextChar = 0x0008, sfIgnoreNextChar = 0x0008,
sfCaretVisible = 0x0010, sfCaretVisible = 0x0010,
sfDblClicked = 0x0020, sfDblClicked = 0x0020,
sfWaitForDragging = 0x0040 sfWaitForDragging = 0x0040,
sfRedrawNeeded = 0x0080,
sfGutterRedrawNeeded = 0x0100,
}; };
Q_DECLARE_FLAGS(StateFlags,StateFlag) Q_DECLARE_FLAGS(StateFlags,StateFlag)
@ -271,6 +273,8 @@ public:
void addGroupBreak(); void addGroupBreak();
void beginEditing(); void beginEditing();
void endEditing(); void endEditing();
void beginSetting();
void endSetting();
void addCaretToUndo(); void addCaretToUndo();
void addLeftTopToUndo(); void addLeftTopToUndo();
void addSelectionToUndo(); void addSelectionToUndo();
@ -498,6 +502,8 @@ protected:
protected: protected:
void doSelectLine(); void doSelectLine();
void incPaintLock();
void decPaintLock();
private: private:
BufferCoord ensureBufferCoordValid(const BufferCoord& coord); BufferCoord ensureBufferCoordValid(const BufferCoord& coord);
void beginEditingWithoutUndo(); void beginEditingWithoutUndo();
@ -506,8 +512,7 @@ private:
void computeCaret(); void computeCaret();
void computeScroll(bool isDragging); void computeScroll(bool isDragging);
void incPaintLock();
void decPaintLock();
int clientWidth() const; int clientWidth() const;
int clientHeight() const; int clientHeight() const;
int clientTop() const; int clientTop() const;
@ -743,6 +748,7 @@ private:
int mPaintTransientLock; int mPaintTransientLock;
bool mIsScrolling; bool mIsScrolling;
int mPainterLock; // lock counter to prevent repaint while painting int mPainterLock; // lock counter to prevent repaint while painting
int mOptionLock; // lock counter to prevent recalculate glyph widths while change settings;
bool mUndoing; bool mUndoing;
// event handlers // event handlers
// ProcessCommandProc mOnCommandProcessed; // ProcessCommandProc mOnCommandProcessed;