fix #370 : Can't correctly undo/redo "Delete current line".

This commit is contained in:
Roy Qu 2024-04-04 19:55:48 +08:00
parent 1fafd2c273
commit 726043d144
2 changed files with 32 additions and 37 deletions

View File

@ -114,6 +114,7 @@ Red Panda C++ Version 2.27
- enhancement: Support "extern template" in code parser. - enhancement: Support "extern template" in code parser.
- enhancement: Set shortcuts for tools menu item. - enhancement: Set shortcuts for tools menu item.
- enhancement: Enhancement for custom tools. - enhancement: Enhancement for custom tools.
- fix: Can't correctly undo/redo "Delete current line".
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

@ -1964,46 +1964,40 @@ void QSynEdit::doDeleteFromBOL()
void QSynEdit::doDeleteLine() void QSynEdit::doDeleteLine()
{ {
if (!mReadOnly && (mDocument->count() > 0)) { if (mReadOnly || (mDocument->count() <= 0))
PCodeFoldingRange foldRange=foldStartAtLine(mCaretY); return;
if (foldRange && foldRange->collapsed) PCodeFoldingRange foldRange=foldStartAtLine(mCaretY);
return; if (foldRange && foldRange->collapsed)
beginEditing(); return;
addCaretToUndo(); beginEditing();
addSelectionToUndo(); addCaretToUndo();
if (selAvail()) addSelectionToUndo();
setBlockBegin(caretXY()); if (selAvail())
QStringList helper(lineText()); setBlockBegin(caretXY());
if (mCaretY == mDocument->count()) { int oldCaretY = caretY();
if (mDocument->count()==1) { bool isLastLine = (oldCaretY >= mDocument->count());
mDocument->putLine(mCaretY - 1,""); bool isFirstLine = (oldCaretY == 1);
mUndoList->addChange(ChangeReason::Delete, BufferCoord startPos;
BufferCoord{1, mCaretY}, BufferCoord endPos;
BufferCoord{helper.length() + 1, mCaretY}, if (isLastLine) {
helper, SelectionMode::Normal); if (isFirstLine) {
} else { startPos.ch = 1;
QString s = mDocument->getLine(mCaretY-2); startPos.line = oldCaretY;
mDocument->deleteAt(mCaretY - 1);
helper.insert(0,"");
mUndoList->addChange(ChangeReason::Delete,
BufferCoord{s.length()+1, mCaretY-1},
BufferCoord{helper.length() + 1, mCaretY},
helper, SelectionMode::Normal);
doLinesDeleted(mCaretY, 1);
mCaretY--;
}
} else { } else {
mDocument->deleteAt(mCaretY - 1); startPos.ch = mDocument->getLine(oldCaretY-2).length()+1;
helper.append(""); startPos.line = oldCaretY-1;
mUndoList->addChange(ChangeReason::Delete,
BufferCoord{1, mCaretY},
BufferCoord{helper.length() + 1, mCaretY},
helper, SelectionMode::Normal);
doLinesDeleted(mCaretY, 1);
} }
endEditing(); endPos.ch = lineText().length()+1;
internalSetCaretXY(BufferCoord{1, mCaretY}); // like seen in the Delphi editor endPos.line = oldCaretY;
} else {
startPos.ch = 1;
startPos.line = oldCaretY;
endPos.ch = 1;
endPos.line = oldCaretY+1;
} }
doDeleteText(startPos, endPos, SelectionMode::Normal);
endEditing();
internalSetCaretXY(BufferCoord{1, oldCaretY});
} }
void QSynEdit::doSelectLine() void QSynEdit::doSelectLine()