fix #370 : Can't correctly undo/redo "Delete current line".
This commit is contained in:
parent
1fafd2c273
commit
726043d144
1
NEWS.md
1
NEWS.md
|
@ -114,6 +114,7 @@ Red Panda C++ Version 2.27
|
|||
- enhancement: Support "extern template" in code parser.
|
||||
- enhancement: Set shortcuts for tools menu item.
|
||||
- enhancement: Enhancement for custom tools.
|
||||
- fix: Can't correctly undo/redo "Delete current line".
|
||||
|
||||
Red Panda C++ Version 2.26
|
||||
- enhancement: Code suggestion for embedded std::vectors.
|
||||
|
|
|
@ -1964,7 +1964,8 @@ void QSynEdit::doDeleteFromBOL()
|
|||
|
||||
void QSynEdit::doDeleteLine()
|
||||
{
|
||||
if (!mReadOnly && (mDocument->count() > 0)) {
|
||||
if (mReadOnly || (mDocument->count() <= 0))
|
||||
return;
|
||||
PCodeFoldingRange foldRange=foldStartAtLine(mCaretY);
|
||||
if (foldRange && foldRange->collapsed)
|
||||
return;
|
||||
|
@ -1973,37 +1974,30 @@ void QSynEdit::doDeleteLine()
|
|||
addSelectionToUndo();
|
||||
if (selAvail())
|
||||
setBlockBegin(caretXY());
|
||||
QStringList helper(lineText());
|
||||
if (mCaretY == mDocument->count()) {
|
||||
if (mDocument->count()==1) {
|
||||
mDocument->putLine(mCaretY - 1,"");
|
||||
mUndoList->addChange(ChangeReason::Delete,
|
||||
BufferCoord{1, mCaretY},
|
||||
BufferCoord{helper.length() + 1, mCaretY},
|
||||
helper, SelectionMode::Normal);
|
||||
int oldCaretY = caretY();
|
||||
bool isLastLine = (oldCaretY >= mDocument->count());
|
||||
bool isFirstLine = (oldCaretY == 1);
|
||||
BufferCoord startPos;
|
||||
BufferCoord endPos;
|
||||
if (isLastLine) {
|
||||
if (isFirstLine) {
|
||||
startPos.ch = 1;
|
||||
startPos.line = oldCaretY;
|
||||
} else {
|
||||
QString s = mDocument->getLine(mCaretY-2);
|
||||
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--;
|
||||
startPos.ch = mDocument->getLine(oldCaretY-2).length()+1;
|
||||
startPos.line = oldCaretY-1;
|
||||
}
|
||||
endPos.ch = lineText().length()+1;
|
||||
endPos.line = oldCaretY;
|
||||
} else {
|
||||
mDocument->deleteAt(mCaretY - 1);
|
||||
helper.append("");
|
||||
mUndoList->addChange(ChangeReason::Delete,
|
||||
BufferCoord{1, mCaretY},
|
||||
BufferCoord{helper.length() + 1, mCaretY},
|
||||
helper, SelectionMode::Normal);
|
||||
doLinesDeleted(mCaretY, 1);
|
||||
startPos.ch = 1;
|
||||
startPos.line = oldCaretY;
|
||||
endPos.ch = 1;
|
||||
endPos.line = oldCaretY+1;
|
||||
}
|
||||
doDeleteText(startPos, endPos, SelectionMode::Normal);
|
||||
endEditing();
|
||||
internalSetCaretXY(BufferCoord{1, mCaretY}); // like seen in the Delphi editor
|
||||
}
|
||||
internalSetCaretXY(BufferCoord{1, oldCaretY});
|
||||
}
|
||||
|
||||
void QSynEdit::doSelectLine()
|
||||
|
|
Loading…
Reference in New Issue