- fix: undo one symbol completion as a whole operation

This commit is contained in:
Roy Qu 2022-03-07 20:51:56 +08:00
parent 1b8f3de21f
commit b436312d19
4 changed files with 28 additions and 0 deletions

View File

@ -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 speed of mouse selection/drag is too fast.
- fix: the scroll behavior of mouse dragging on the editor's edge is not correct - 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: calculation of caret position is not in consistence.
- fix: undo one symbol completion as a whole operation
Red Panda C++ Version 0.14.4 Red Panda C++ Version 0.14.4
- enhancement: git - log - enhancement: git - log

View File

@ -2053,10 +2053,12 @@ bool Editor::handleParentheseCompletion()
QuoteStatus status = getQuoteStatus(); QuoteStatus status = getQuoteStatus();
if (status == QuoteStatus::RawString || status == QuoteStatus::NotQuote) { if (status == QuoteStatus::RawString || status == QuoteStatus::NotQuote) {
beginUpdate(); beginUpdate();
beginUndoBlock();
commandProcessor(SynEditorCommand::ecChar,'('); commandProcessor(SynEditorCommand::ecChar,'(');
BufferCoord oldCaret = caretXY(); BufferCoord oldCaret = caretXY();
commandProcessor(SynEditorCommand::ecChar,')'); commandProcessor(SynEditorCommand::ecChar,')');
setCaretXY(oldCaret); setCaretXY(oldCaret);
endUndoBlock();
endUpdate(); endUpdate();
return true; return true;
} }
@ -2102,10 +2104,12 @@ bool Editor::handleBracketCompletion()
// QuoteStatus status = getQuoteStatus(); // QuoteStatus status = getQuoteStatus();
// if (status == QuoteStatus::RawString || status == QuoteStatus::NotQuote) { // if (status == QuoteStatus::RawString || status == QuoteStatus::NotQuote) {
beginUpdate(); beginUpdate();
beginUndoBlock();
commandProcessor(SynEditorCommand::ecChar,'['); commandProcessor(SynEditorCommand::ecChar,'[');
BufferCoord oldCaret = caretXY(); BufferCoord oldCaret = caretXY();
commandProcessor(SynEditorCommand::ecChar,']'); commandProcessor(SynEditorCommand::ecChar,']');
setCaretXY(oldCaret); setCaretXY(oldCaret);
endUndoBlock();
endUpdate(); endUpdate();
return true; return true;
// } // }
@ -2136,11 +2140,13 @@ bool Editor::handleMultilineCommentCompletion()
{ {
if ((caretX()-2 < lineText().length()) && (lineText()[caretX() - 2] == '/')) { if ((caretX()-2 < lineText().length()) && (lineText()[caretX() - 2] == '/')) {
beginUpdate(); beginUpdate();
beginUndoBlock();
commandProcessor(SynEditorCommand::ecChar,'*'); commandProcessor(SynEditorCommand::ecChar,'*');
BufferCoord oldCaret = caretXY(); BufferCoord oldCaret = caretXY();
commandProcessor(SynEditorCommand::ecChar,'*'); commandProcessor(SynEditorCommand::ecChar,'*');
commandProcessor(SynEditorCommand::ecChar,'/'); commandProcessor(SynEditorCommand::ecChar,'/');
setCaretXY(oldCaret); setCaretXY(oldCaret);
endUndoBlock();
endUpdate(); endUpdate();
return true; return true;
} }
@ -2156,6 +2162,7 @@ bool Editor::handleBraceCompletion()
i--; i--;
} }
beginUpdate(); beginUpdate();
beginUndoBlock();
commandProcessor(SynEditorCommand::ecChar,'{'); commandProcessor(SynEditorCommand::ecChar,'{');
BufferCoord oldCaret = caretXY(); BufferCoord oldCaret = caretXY();
commandProcessor(SynEditorCommand::ecChar,'}'); commandProcessor(SynEditorCommand::ecChar,'}');
@ -2172,6 +2179,7 @@ bool Editor::handleBraceCompletion()
commandProcessor(SynEditorCommand::ecChar,';'); commandProcessor(SynEditorCommand::ecChar,';');
} }
setCaretXY(oldCaret); setCaretXY(oldCaret);
endUndoBlock();
endUpdate(); endUpdate();
return true; return true;
} }
@ -2218,10 +2226,12 @@ bool Editor::handleSingleQuoteCompletion()
if (ch == 0 || highlighter()->isWordBreakChar(ch) || highlighter()->isSpaceChar(ch)) { if (ch == 0 || highlighter()->isWordBreakChar(ch) || highlighter()->isSpaceChar(ch)) {
// insert '' // insert ''
beginUpdate(); beginUpdate();
beginUndoBlock();
commandProcessor(SynEditorCommand::ecChar,'\''); commandProcessor(SynEditorCommand::ecChar,'\'');
BufferCoord oldCaret = caretXY(); BufferCoord oldCaret = caretXY();
commandProcessor(SynEditorCommand::ecChar,'\''); commandProcessor(SynEditorCommand::ecChar,'\'');
setCaretXY(oldCaret); setCaretXY(oldCaret);
endUndoBlock();
endUpdate(); endUpdate();
return true; return true;
} }
@ -2244,10 +2254,12 @@ bool Editor::handleDoubleQuoteCompletion()
if ((ch == 0) || highlighter()->isWordBreakChar(ch) || highlighter()->isSpaceChar(ch)) { if ((ch == 0) || highlighter()->isWordBreakChar(ch) || highlighter()->isSpaceChar(ch)) {
// insert "" // insert ""
beginUpdate(); beginUpdate();
beginUndoBlock();
commandProcessor(SynEditorCommand::ecChar,'"'); commandProcessor(SynEditorCommand::ecChar,'"');
BufferCoord oldCaret = caretXY(); BufferCoord oldCaret = caretXY();
commandProcessor(SynEditorCommand::ecChar,'"'); commandProcessor(SynEditorCommand::ecChar,'"');
setCaretXY(oldCaret); setCaretXY(oldCaret);
endUndoBlock();
endUpdate(); endUpdate();
return true; return true;
} }
@ -2264,11 +2276,13 @@ bool Editor::handleGlobalIncludeCompletion()
if (!s.startsWith("include")) //it's not #include if (!s.startsWith("include")) //it's not #include
return false; return false;
beginUpdate(); beginUpdate();
beginUndoBlock();
commandProcessor(SynEditorCommand::ecChar,'<'); commandProcessor(SynEditorCommand::ecChar,'<');
BufferCoord oldCaret = caretXY(); BufferCoord oldCaret = caretXY();
commandProcessor(SynEditorCommand::ecChar,'>'); commandProcessor(SynEditorCommand::ecChar,'>');
setCaretXY(oldCaret); setCaretXY(oldCaret);
endUpdate(); endUpdate();
endUndoBlock();
return true; return true;
} }

View File

@ -441,6 +441,16 @@ bool SynEdit::getHighlighterAttriAtRowColEx(const BufferCoord &XY, QString &Toke
return false; return false;
} }
void SynEdit::beginUndoBlock()
{
mUndoList->BeginBlock();
}
void SynEdit::endUndoBlock()
{
mUndoList->EndBlock();
}
void SynEdit::beginUpdate() void SynEdit::beginUpdate()
{ {
incPaintLock(); incPaintLock();

View File

@ -259,6 +259,9 @@ public:
SynHighlighterTokenType& TokenType, SynTokenKind &TokenKind, int &Start, SynHighlighterTokenType& TokenType, SynTokenKind &TokenKind, int &Start,
PSynHighlighterAttribute& Attri); PSynHighlighterAttribute& Attri);
void beginUndoBlock();
void endUndoBlock();
//Commands //Commands
virtual void cutToClipboard() { commandProcessor(SynEditorCommand::ecCut);} virtual void cutToClipboard() { commandProcessor(SynEditorCommand::ecCut);}
virtual void copyToClipboard() { commandProcessor(SynEditorCommand::ecCopy);} virtual void copyToClipboard() { commandProcessor(SynEditorCommand::ecCopy);}