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