fix: undo chains

This commit is contained in:
Roy Qu 2022-07-03 13:08:14 +08:00
parent 76f0b9d17b
commit 7ba5f3e5c8
2 changed files with 17 additions and 5 deletions

View File

@ -8,6 +8,7 @@ Red Panda C++ Version 1.1.4
- enhancement: only allow delete whole folded code block - enhancement: only allow delete whole folded code block
- refactor of undo system - refactor of undo system
- fix: calculation of the code block ranges when inserting/deleting - fix: calculation of the code block ranges when inserting/deleting
- fix: undo chains
Red Panda C++ Version 1.1.3 Red Panda C++ Version 1.1.3

View File

@ -2428,11 +2428,15 @@ void SynEdit::insertLine(bool moveCaret)
if (mReadOnly) if (mReadOnly)
return; return;
int nLinesInserted=0; int nLinesInserted=0;
if (!mUndoing) if (!mUndoing) {
qDebug()<<"begin";
mUndoList->BeginBlock(); mUndoList->BeginBlock();
}
auto action = finally([this] { auto action = finally([this] {
if (!mUndoing) if (!mUndoing) {
qDebug()<<"end";
mUndoList->EndBlock(); mUndoList->EndBlock();
}
}); });
QString helper; QString helper;
if (selAvail()) { if (selAvail()) {
@ -2448,6 +2452,7 @@ void SynEdit::insertLine(bool moveCaret)
QString s = Temp+highlighter()->foldString(); QString s = Temp+highlighter()->foldString();
if (mCaretX > s.length()) { if (mCaretX > s.length()) {
if (!mUndoing) { if (!mUndoing) {
qDebug()<<"caret";
addCaretToUndo(); addCaretToUndo();
addSelectionToUndo(); addSelectionToUndo();
} }
@ -2497,9 +2502,11 @@ void SynEdit::insertLine(bool moveCaret)
QString indentSpacesForRightLineText = GetLeftSpacing(indentSpaces,true); QString indentSpacesForRightLineText = GetLeftSpacing(indentSpaces,true);
mDocument->insert(mCaretY, indentSpacesForRightLineText+rightLineText); mDocument->insert(mCaretY, indentSpacesForRightLineText+rightLineText);
nLinesInserted++; nLinesInserted++;
if (!mUndoing) if (!mUndoing) {
qDebug()<<"linebreak";
mUndoList->AddChange(SynChangeReason::crLineBreak, caretXY(), caretXY(), QStringList(rightLineText), mUndoList->AddChange(SynChangeReason::crLineBreak, caretXY(), caretXY(), QStringList(rightLineText),
SynSelectionMode::smNormal); SynSelectionMode::smNormal);
}
if (!mUndoing) { if (!mUndoing) {
//insert new line in middle of "/*" and "*/" //insert new line in middle of "/*" and "*/"
@ -3627,7 +3634,6 @@ void SynEdit::rescanForFoldRanges()
PSynEditFoldRanges TemporaryAllFoldRanges = std::make_shared<SynEditFoldRanges>(); PSynEditFoldRanges TemporaryAllFoldRanges = std::make_shared<SynEditFoldRanges>();
scanForFoldRanges(TemporaryAllFoldRanges); scanForFoldRanges(TemporaryAllFoldRanges);
qDebug()<<" ------- ";
// Combine new with old folds, preserve parent order // Combine new with old folds, preserve parent order
for (int i = 0; i< TemporaryAllFoldRanges->count();i++) { for (int i = 0; i< TemporaryAllFoldRanges->count();i++) {
PSynEditFoldRange tempFoldRange=TemporaryAllFoldRanges->range(i); PSynEditFoldRange tempFoldRange=TemporaryAllFoldRanges->range(i);
@ -4363,6 +4369,7 @@ void SynEdit::doUndo()
FKeepGoing = (mOptions.testFlag(eoGroupUndo) && FKeepGoing = (mOptions.testFlag(eoGroupUndo) &&
(FLastChange == Item->changeReason()) ); (FLastChange == Item->changeReason()) );
} }
OldChangeNumber=Item->changeNumber();
FLastChange = Item->changeReason(); FLastChange = Item->changeReason();
} }
} while (FKeepGoing); } while (FKeepGoing);
@ -4489,7 +4496,7 @@ void SynEdit::doUndoItem()
Item->changeReason(), Item->changeReason(),
Item->changeStartPos(), Item->changeStartPos(),
Item->changeEndPos(), Item->changeEndPos(),
QStringList(), Item->changeText(),
Item->changeSelMode()); Item->changeSelMode());
break; break;
} }
@ -4534,6 +4541,7 @@ void SynEdit::doRedo()
FKeepGoing = (mOptions.testFlag(eoGroupUndo) && FKeepGoing = (mOptions.testFlag(eoGroupUndo) &&
(FLastChange == Item->changeReason())); (FLastChange == Item->changeReason()));
} }
OldChangeNumber=Item->changeNumber();
FLastChange = Item->changeReason(); FLastChange = Item->changeReason();
} }
} while (FKeepGoing); } while (FKeepGoing);
@ -4652,6 +4660,9 @@ void SynEdit::doRedoItem()
}; };
case SynChangeReason::crLineBreak: { case SynChangeReason::crLineBreak: {
BufferCoord CaretPt = Item->changeStartPos(); BufferCoord CaretPt = Item->changeStartPos();
mUndoList->AddChange(Item->changeReason(), Item->changeStartPos(),
Item->changeEndPos(),Item->changeText(),
Item->changeSelMode());
setCaretAndSelection(CaretPt, CaretPt, CaretPt); setCaretAndSelection(CaretPt, CaretPt, CaretPt);
commandProcessor(SynEditorCommand::ecLineBreak); commandProcessor(SynEditorCommand::ecLineBreak);
break; break;