rename symbol/batch replace correctly support undo
This commit is contained in:
parent
bc1b22ad25
commit
93a37a2bc6
|
@ -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 {
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -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);
|
||||
|
||||
|
|
Loading…
Reference in New Issue