- enhancement: group undo will stop at spaces

This commit is contained in:
Roy Qu 2022-03-01 23:35:01 +08:00
parent ee59d80bdb
commit 74efa484be
4 changed files with 26 additions and 2 deletions

View File

@ -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

View File

@ -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();

View File

@ -845,6 +845,11 @@ SynChangeReason SynEditUndoList::LastChangeReason()
return mItems.last()->changeReason();
}
bool SynEditUndoList::isEmpty()
{
return mItems.count()==0;
}
void SynEditUndoList::Lock()
{
mLockCount++;

View File

@ -202,6 +202,7 @@ public:
void DeleteItem(int index);
void EndBlock();
SynChangeReason LastChangeReason();
bool isEmpty();
void Lock();
PSynEditUndoItem PeekItem();
PSynEditUndoItem PopItem();