diff --git a/RedPandaIDE/cpprefacter.cpp b/RedPandaIDE/cpprefacter.cpp index b67d6a4a..3cc51f53 100644 --- a/RedPandaIDE/cpprefacter.cpp +++ b/RedPandaIDE/cpprefacter.cpp @@ -281,6 +281,9 @@ void CppRefacter::renameSymbolInFile(const QString &filename, const PStatement & if (oldEditor){ QSynedit::PSyntaxer syntaxer = syntaxerManager.getSyntaxer(QSynedit::ProgrammingLanguage::CPP); int posY = 0; + oldEditor->clearSelection(); + oldEditor->addGroupBreak(); + oldEditor->beginUndoBlock(); while (posY < oldEditor->document()->count()) { QString line = oldEditor->document()->getLine(posY); if (posY == 0) { @@ -317,6 +320,7 @@ void CppRefacter::renameSymbolInFile(const QString &filename, const PStatement & oldEditor->replaceLine(posY+1,newLine); posY++; } + oldEditor->endUndoBlock(); } else { Editor editor(nullptr); QByteArray encoding; @@ -326,7 +330,6 @@ void CppRefacter::renameSymbolInFile(const QString &filename, const PStatement & int posY = 0; while (posY < editor.document()->count()) { QString line = editor.document()->getLine(posY); - if (posY == 0) { editor.syntaxer()->resetState(); } else { diff --git a/RedPandaIDE/mainwindow.cpp b/RedPandaIDE/mainwindow.cpp index a9e49ec7..6a0fa032 100644 --- a/RedPandaIDE/mainwindow.cpp +++ b/RedPandaIDE/mainwindow.cpp @@ -7713,6 +7713,9 @@ void MainWindow::on_btnReplace_clicked() tr("Can't open file '%1' for replace!").arg(file->filename)); return; } + editor->clearSelection(); + editor->addGroupBreak(); + editor->beginUndoBlock(); for (int i=file->results.count()-1;i>=0;i--) { const PSearchResultTreeItem& item = file->results[i]; if (!item->selected) @@ -7722,12 +7725,14 @@ void MainWindow::on_btnReplace_clicked() QMessageBox::critical(editor, tr("Replace Error"), tr("Contents has changed since last search!")); + editor->endUndoBlock(); return; } line.remove(item->start-1,results->keyword.length()); line.insert(item->start-1, newWord); editor->replaceLine(item->line,line); } + editor->endUndoBlock(); } showSearchReplacePanel(false); stretchMessagesPanel(false); diff --git a/libs/qsynedit/qsynedit/qsynedit.cpp b/libs/qsynedit/qsynedit/qsynedit.cpp index 8b10949b..5dc263d2 100644 --- a/libs/qsynedit/qsynedit/qsynedit.cpp +++ b/libs/qsynedit/qsynedit/qsynedit.cpp @@ -431,6 +431,11 @@ bool QSynEdit::getTokenAttriAtRowColEx(const BufferCoord &pos, QString &token, i return false; } +void QSynEdit::addGroupBreak() +{ + mUndoList->addGroupBreak(); +} + void QSynEdit::beginUndoBlock() { mUndoList->beginBlock(); @@ -6787,6 +6792,12 @@ BufferCoord QSynEdit::blockEnd() const return mBlockEnd; } +void QSynEdit::clearSelection() +{ + setActiveSelectionMode(SelectionMode::Normal); + setBlockBegin(caretXY()); +} + void QSynEdit::setBlockEnd(BufferCoord value) { //setActiveSelectionMode(mSelectionMode); diff --git a/libs/qsynedit/qsynedit/qsynedit.h b/libs/qsynedit/qsynedit/qsynedit.h index 5eb37c3d..5e33492e 100644 --- a/libs/qsynedit/qsynedit/qsynedit.h +++ b/libs/qsynedit/qsynedit/qsynedit.h @@ -249,6 +249,7 @@ public: bool getTokenAttriAtRowColEx(const BufferCoord& pos, QString& token, int &start, PTokenAttribute& attri); + void addGroupBreak(); void beginUndoBlock(); void endUndoBlock(); void addCaretToUndo(); @@ -320,6 +321,7 @@ public: BufferCoord blockBegin() const; BufferCoord blockEnd() const; + void clearSelection(); void setBlockBegin(BufferCoord value); void setBlockEnd(BufferCoord Value);