From b436312d195befbfaccdddbdcf22c5dcd827dc18 Mon Sep 17 00:00:00 2001 From: Roy Qu Date: Mon, 7 Mar 2022 20:51:56 +0800 Subject: [PATCH] - fix: undo one symbol completion as a whole operation --- NEWS.md | 1 + RedPandaIDE/editor.cpp | 14 ++++++++++++++ RedPandaIDE/qsynedit/SynEdit.cpp | 10 ++++++++++ RedPandaIDE/qsynedit/SynEdit.h | 3 +++ 4 files changed, 28 insertions(+) diff --git a/NEWS.md b/NEWS.md index d8b71601..0e2c4367 100644 --- a/NEWS.md +++ b/NEWS.md @@ -18,6 +18,7 @@ Red Panda C++ Version 0.14.5 - fix: the scroll speed of mouse selection/drag is too fast. - fix: the scroll behavior of mouse dragging on the editor's edge is not correct - fix: calculation of caret position is not in consistence. + - fix: undo one symbol completion as a whole operation Red Panda C++ Version 0.14.4 - enhancement: git - log diff --git a/RedPandaIDE/editor.cpp b/RedPandaIDE/editor.cpp index 9de1a001..66b586de 100644 --- a/RedPandaIDE/editor.cpp +++ b/RedPandaIDE/editor.cpp @@ -2053,10 +2053,12 @@ bool Editor::handleParentheseCompletion() QuoteStatus status = getQuoteStatus(); if (status == QuoteStatus::RawString || status == QuoteStatus::NotQuote) { beginUpdate(); + beginUndoBlock(); commandProcessor(SynEditorCommand::ecChar,'('); BufferCoord oldCaret = caretXY(); commandProcessor(SynEditorCommand::ecChar,')'); setCaretXY(oldCaret); + endUndoBlock(); endUpdate(); return true; } @@ -2102,10 +2104,12 @@ bool Editor::handleBracketCompletion() // QuoteStatus status = getQuoteStatus(); // if (status == QuoteStatus::RawString || status == QuoteStatus::NotQuote) { beginUpdate(); + beginUndoBlock(); commandProcessor(SynEditorCommand::ecChar,'['); BufferCoord oldCaret = caretXY(); commandProcessor(SynEditorCommand::ecChar,']'); setCaretXY(oldCaret); + endUndoBlock(); endUpdate(); return true; // } @@ -2136,11 +2140,13 @@ bool Editor::handleMultilineCommentCompletion() { if ((caretX()-2 < lineText().length()) && (lineText()[caretX() - 2] == '/')) { beginUpdate(); + beginUndoBlock(); commandProcessor(SynEditorCommand::ecChar,'*'); BufferCoord oldCaret = caretXY(); commandProcessor(SynEditorCommand::ecChar,'*'); commandProcessor(SynEditorCommand::ecChar,'/'); setCaretXY(oldCaret); + endUndoBlock(); endUpdate(); return true; } @@ -2156,6 +2162,7 @@ bool Editor::handleBraceCompletion() i--; } beginUpdate(); + beginUndoBlock(); commandProcessor(SynEditorCommand::ecChar,'{'); BufferCoord oldCaret = caretXY(); commandProcessor(SynEditorCommand::ecChar,'}'); @@ -2172,6 +2179,7 @@ bool Editor::handleBraceCompletion() commandProcessor(SynEditorCommand::ecChar,';'); } setCaretXY(oldCaret); + endUndoBlock(); endUpdate(); return true; } @@ -2218,10 +2226,12 @@ bool Editor::handleSingleQuoteCompletion() if (ch == 0 || highlighter()->isWordBreakChar(ch) || highlighter()->isSpaceChar(ch)) { // insert '' beginUpdate(); + beginUndoBlock(); commandProcessor(SynEditorCommand::ecChar,'\''); BufferCoord oldCaret = caretXY(); commandProcessor(SynEditorCommand::ecChar,'\''); setCaretXY(oldCaret); + endUndoBlock(); endUpdate(); return true; } @@ -2244,10 +2254,12 @@ bool Editor::handleDoubleQuoteCompletion() if ((ch == 0) || highlighter()->isWordBreakChar(ch) || highlighter()->isSpaceChar(ch)) { // insert "" beginUpdate(); + beginUndoBlock(); commandProcessor(SynEditorCommand::ecChar,'"'); BufferCoord oldCaret = caretXY(); commandProcessor(SynEditorCommand::ecChar,'"'); setCaretXY(oldCaret); + endUndoBlock(); endUpdate(); return true; } @@ -2264,11 +2276,13 @@ bool Editor::handleGlobalIncludeCompletion() if (!s.startsWith("include")) //it's not #include return false; beginUpdate(); + beginUndoBlock(); commandProcessor(SynEditorCommand::ecChar,'<'); BufferCoord oldCaret = caretXY(); commandProcessor(SynEditorCommand::ecChar,'>'); setCaretXY(oldCaret); endUpdate(); + endUndoBlock(); return true; } diff --git a/RedPandaIDE/qsynedit/SynEdit.cpp b/RedPandaIDE/qsynedit/SynEdit.cpp index 1bc05bca..804f12e0 100644 --- a/RedPandaIDE/qsynedit/SynEdit.cpp +++ b/RedPandaIDE/qsynedit/SynEdit.cpp @@ -441,6 +441,16 @@ bool SynEdit::getHighlighterAttriAtRowColEx(const BufferCoord &XY, QString &Toke return false; } +void SynEdit::beginUndoBlock() +{ + mUndoList->BeginBlock(); +} + +void SynEdit::endUndoBlock() +{ + mUndoList->EndBlock(); +} + void SynEdit::beginUpdate() { incPaintLock(); diff --git a/RedPandaIDE/qsynedit/SynEdit.h b/RedPandaIDE/qsynedit/SynEdit.h index 30f940eb..24d2029e 100644 --- a/RedPandaIDE/qsynedit/SynEdit.h +++ b/RedPandaIDE/qsynedit/SynEdit.h @@ -259,6 +259,9 @@ public: SynHighlighterTokenType& TokenType, SynTokenKind &TokenKind, int &Start, PSynHighlighterAttribute& Attri); + void beginUndoBlock(); + void endUndoBlock(); + //Commands virtual void cutToClipboard() { commandProcessor(SynEditorCommand::ecCut);} virtual void copyToClipboard() { commandProcessor(SynEditorCommand::ecCopy);}