From 74efa484beca5d6d2c44f80a08261b9b9ce364c6 Mon Sep 17 00:00:00 2001 From: Roy Qu Date: Tue, 1 Mar 2022 23:35:01 +0800 Subject: [PATCH] - enhancement: group undo will stop at spaces --- NEWS.md | 1 + RedPandaIDE/qsynedit/SynEdit.cpp | 21 +++++++++++++++++++-- RedPandaIDE/qsynedit/TextBuffer.cpp | 5 +++++ RedPandaIDE/qsynedit/TextBuffer.h | 1 + 4 files changed, 26 insertions(+), 2 deletions(-) diff --git a/NEWS.md b/NEWS.md index 81ff8896..6381c363 100644 --- a/NEWS.md +++ b/NEWS.md @@ -8,6 +8,7 @@ Red Panda C++ Version 0.14.5 - enhancement: enable group undo - enhancement: add option "hide symbols start with underscore" and "hide synbols start with two underscore" - fix: can't rename project files that not openned in editor + - enhancement: group undo will stop at spaces Red Panda C++ Version 0.14.4 diff --git a/RedPandaIDE/qsynedit/SynEdit.cpp b/RedPandaIDE/qsynedit/SynEdit.cpp index f80d9b2f..c9e2aca0 100644 --- a/RedPandaIDE/qsynedit/SynEdit.cpp +++ b/RedPandaIDE/qsynedit/SynEdit.cpp @@ -2683,7 +2683,19 @@ void SynEdit::doAddChar(QChar AChar) if (isIdentChar(AChar)) { doSetSelText(AChar); - } else { + } else if (AChar.isSpace()) { + // break group undo chain + mUndoList->AddChange(SynChangeReason::crNothing, + BufferCoord{0, 0}, + BufferCoord{0, 0}, + "", SynSelectionMode::smNormal); + doSetSelText(AChar); + // break group undo chain + mUndoList->AddChange(SynChangeReason::crNothing, + BufferCoord{0, 0}, + BufferCoord{0, 0}, + "", SynSelectionMode::smNormal); + }else { mUndoList->BeginBlock(); doSetSelText(AChar); int oldCaretX=mCaretX-1; @@ -4040,11 +4052,16 @@ void SynEdit::doUndo() int OldChangeNumber = Item->changeNumber(); int SaveChangeNumber = mRedoList->blockChangeNumber(); mRedoList->setBlockChangeNumber(Item->changeNumber()); - { auto action = finally([&,this] { mRedoList->setBlockChangeNumber(SaveChangeNumber); }); + //skip group chain breakers + if (mUndoList->LastChangeReason()==SynChangeReason::crNothing) { + while (!mUndoList->isEmpty() && mUndoList->LastChangeReason()==SynChangeReason::crNothing) { + doUndoItem(); + } + } do { doUndoItem(); Item = mUndoList->PeekItem(); diff --git a/RedPandaIDE/qsynedit/TextBuffer.cpp b/RedPandaIDE/qsynedit/TextBuffer.cpp index 4ca7f828..769a89eb 100644 --- a/RedPandaIDE/qsynedit/TextBuffer.cpp +++ b/RedPandaIDE/qsynedit/TextBuffer.cpp @@ -845,6 +845,11 @@ SynChangeReason SynEditUndoList::LastChangeReason() return mItems.last()->changeReason(); } +bool SynEditUndoList::isEmpty() +{ + return mItems.count()==0; +} + void SynEditUndoList::Lock() { mLockCount++; diff --git a/RedPandaIDE/qsynedit/TextBuffer.h b/RedPandaIDE/qsynedit/TextBuffer.h index f18f3eb1..477270ea 100644 --- a/RedPandaIDE/qsynedit/TextBuffer.h +++ b/RedPandaIDE/qsynedit/TextBuffer.h @@ -202,6 +202,7 @@ public: void DeleteItem(int index); void EndBlock(); SynChangeReason LastChangeReason(); + bool isEmpty(); void Lock(); PSynEditUndoItem PeekItem(); PSynEditUndoItem PopItem();