From 3ba5811edfa9af4ef9a1a211177f5b5c36bf209a Mon Sep 17 00:00:00 2001 From: Roy Qu Date: Sat, 26 Mar 2022 11:49:41 +0800 Subject: [PATCH] - enhancement: refine behavior of undo input space char --- NEWS.md | 1 + RedPandaIDE/qsynedit/SynEdit.cpp | 79 +++++++++++++------------------- 2 files changed, 32 insertions(+), 48 deletions(-) diff --git a/NEWS.md b/NEWS.md index 0cbe0317..9fcd3fdb 100644 --- a/NEWS.md +++ b/NEWS.md @@ -1,5 +1,6 @@ Red Panda C++ Version 1.0.2 - enhancement: press tab in column mode won't exit column mode + - enhancement: refine behavior of undo input space char Red Panda C++ Version 1.0.1 - fix: only convert project icon file when it's filename doesn't end with ".ico" diff --git a/RedPandaIDE/qsynedit/SynEdit.cpp b/RedPandaIDE/qsynedit/SynEdit.cpp index fc404915..8cb332d3 100644 --- a/RedPandaIDE/qsynedit/SynEdit.cpp +++ b/RedPandaIDE/qsynedit/SynEdit.cpp @@ -2786,23 +2786,21 @@ void SynEdit::doAddChar(QChar AChar) setSelLength(1); } - bool addInColumnMode = (mActiveSelectionMode == SynSelectionMode::smColumn); - BufferCoord oldBlockBegin = blockBegin(); - BufferCoord oldBlockEnd = blockEnd(); if (isIdentChar(AChar)) { doSetSelText(AChar); } else if (AChar.isSpace()) { // break group undo chain mUndoList->AddChange(SynChangeReason::crNothing, - BufferCoord{0, 0}, - BufferCoord{0, 0}, - "", SynSelectionMode::smNormal); + 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); +// if (mActiveSelectionMode!=SynSelectionMode::smColumn) +// mUndoList->AddChange(SynChangeReason::crNothing, +// BufferCoord{0, 0}, +// BufferCoord{0, 0}, +// "", SynSelectionMode::smNormal); }else { mUndoList->BeginBlock(); doSetSelText(AChar); @@ -2877,13 +2875,6 @@ void SynEdit::doAddChar(QChar AChar) } mUndoList->EndBlock(); } - if (addInColumnMode) { - oldBlockBegin.Char = mCaretX; - oldBlockEnd.Char = mCaretX; - setBlockBegin(oldBlockBegin); - setBlockEnd(oldBlockEnd); - setActiveSelectionMode(SynSelectionMode::smColumn); - } //DoOnPaintTransient(ttAfter); } @@ -4170,17 +4161,7 @@ void SynEdit::doAddStr(const QString &s) setCaretAndSelection(caretXY(),BB,BE); } } - bool addInColumnMode = (mActiveSelectionMode == SynSelectionMode::smColumn); - BufferCoord oldBlockBegin = blockBegin(); - BufferCoord oldBlockEnd = blockEnd(); doSetSelText(s); - if (addInColumnMode) { - oldBlockBegin.Char = mCaretX; - oldBlockEnd.Char = mCaretX; - setBlockBegin(oldBlockBegin); - setBlockEnd(oldBlockEnd); - setActiveSelectionMode(SynSelectionMode::smColumn); - } } void SynEdit::doUndo() @@ -4199,13 +4180,6 @@ void SynEdit::doUndo() mRedoList->AddGroupBreak(); } - SynChangeReason FLastChange = mUndoList->LastChangeReason(); - bool FAutoComplete = (FLastChange == SynChangeReason::crAutoCompleteEnd); - bool FPasteAction = (FLastChange == SynChangeReason::crPasteEnd); - bool FSpecial1 = (FLastChange == SynChangeReason::crSpecial1End); - bool FSpecial2 = (FLastChange == SynChangeReason::crSpecial2End); - bool FKeepGoing; - PSynEditUndoItem Item = mUndoList->PeekItem(); if (Item) { int OldChangeNumber = Item->changeNumber(); @@ -4221,6 +4195,12 @@ void SynEdit::doUndo() doUndoItem(); } } + SynChangeReason FLastChange = mUndoList->LastChangeReason(); + bool FAutoComplete = (FLastChange == SynChangeReason::crAutoCompleteEnd); + bool FPasteAction = (FLastChange == SynChangeReason::crPasteEnd); + bool FSpecial1 = (FLastChange == SynChangeReason::crSpecial1End); + bool FSpecial2 = (FLastChange == SynChangeReason::crSpecial2End); + bool FKeepGoing; do { doUndoItem(); Item = mUndoList->PeekItem(); @@ -4431,12 +4411,6 @@ void SynEdit::doRedo() if (mReadOnly) return; - SynChangeReason FLastChange = mRedoList->LastChangeReason(); - bool FAutoComplete = (FLastChange == SynChangeReason::crAutoCompleteBegin); - bool FPasteAction = (FLastChange == SynChangeReason::crPasteBegin); - bool FSpecial1 = (FLastChange == SynChangeReason::crSpecial1Begin); - bool FSpecial2 = (FLastChange == SynChangeReason::crSpecial2Begin); - PSynEditUndoItem Item = mRedoList->PeekItem(); if (!Item) return; @@ -4453,6 +4427,11 @@ void SynEdit::doRedo() doRedoItem(); } } + SynChangeReason FLastChange = mRedoList->LastChangeReason(); + bool FAutoComplete = (FLastChange == SynChangeReason::crAutoCompleteBegin); + bool FPasteAction = (FLastChange == SynChangeReason::crPasteBegin); + bool FSpecial1 = (FLastChange == SynChangeReason::crSpecial1Begin); + bool FSpecial2 = (FLastChange == SynChangeReason::crSpecial2Begin); bool FKeepGoing; do { doRedoItem(); @@ -4976,11 +4955,6 @@ void SynEdit::setSelTextPrimitiveEx(SynSelectionMode PasteMode, const QString &V BufferCoord BE = blockEnd(); if (selAvail()) { deleteSelection(BB,BE); - if (mActiveSelectionMode == SynSelectionMode::smColumn) { - BE.Char = BB.Char; - mBlockBegin = BB; - mBlockEnd = BE; - } internalSetCaretXY(BB); } if (!Value.isEmpty()) { @@ -6478,9 +6452,18 @@ void SynEdit::onLinesChanged() mStateFlags.setFlag(SynStateFlag::sfLinesChanging, false); updateScrollbars(); - vOldMode = mActiveSelectionMode; - setBlockBegin(caretXY()); - mActiveSelectionMode = vOldMode; + if (mActiveSelectionMode == SynSelectionMode::smColumn) { + BufferCoord oldBlockStart = blockBegin(); + BufferCoord oldBlockEnd = blockEnd(); + oldBlockStart.Char = mCaretX; + oldBlockEnd.Char = mCaretX; + setBlockBegin(oldBlockStart); + setBlockEnd(oldBlockEnd); + } else { + vOldMode = mActiveSelectionMode; + setBlockBegin(caretXY()); + mActiveSelectionMode = vOldMode; + } if (mInvalidateRect.width()==0) invalidate(); else