- 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: enable group undo
- enhancement: add option "hide symbols start with underscore" and "hide synbols start with two underscore" - 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 - 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 Red Panda C++ Version 0.14.4

View File

@ -2683,7 +2683,19 @@ void SynEdit::doAddChar(QChar AChar)
if (isIdentChar(AChar)) { if (isIdentChar(AChar)) {
doSetSelText(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(); mUndoList->BeginBlock();
doSetSelText(AChar); doSetSelText(AChar);
int oldCaretX=mCaretX-1; int oldCaretX=mCaretX-1;
@ -4040,11 +4052,16 @@ void SynEdit::doUndo()
int OldChangeNumber = Item->changeNumber(); int OldChangeNumber = Item->changeNumber();
int SaveChangeNumber = mRedoList->blockChangeNumber(); int SaveChangeNumber = mRedoList->blockChangeNumber();
mRedoList->setBlockChangeNumber(Item->changeNumber()); mRedoList->setBlockChangeNumber(Item->changeNumber());
{ {
auto action = finally([&,this] { auto action = finally([&,this] {
mRedoList->setBlockChangeNumber(SaveChangeNumber); mRedoList->setBlockChangeNumber(SaveChangeNumber);
}); });
//skip group chain breakers
if (mUndoList->LastChangeReason()==SynChangeReason::crNothing) {
while (!mUndoList->isEmpty() && mUndoList->LastChangeReason()==SynChangeReason::crNothing) {
doUndoItem();
}
}
do { do {
doUndoItem(); doUndoItem();
Item = mUndoList->PeekItem(); Item = mUndoList->PeekItem();

View File

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

View File

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