forked from qt-creator/qt-creator
ClangFormat: Do not create extra operations to undo on save
If formatting is applied on save do not create a new replacement for each replacement action. Instead join the last edit block to make it possible to undo the formatting in one go. Change-Id: Ie0cb66eb5e76998e5045c1183f5f796e5a718659 Reviewed-by: Marco Bubke <marco.bubke@qt.io>
This commit is contained in:
@@ -462,6 +462,8 @@ static int formatRange(QTextDocument *doc,
|
|||||||
bool CppEditorDocument::save(QString *errorString, const QString &fileName, bool autoSave)
|
bool CppEditorDocument::save(QString *errorString, const QString &fileName, bool autoSave)
|
||||||
{
|
{
|
||||||
if (indenter()->formatOnSave()) {
|
if (indenter()->formatOnSave()) {
|
||||||
|
QTextCursor cursor(document());
|
||||||
|
cursor.joinPreviousEditBlock();
|
||||||
auto *layout = qobject_cast<TextEditor::TextDocumentLayout *>(document()->documentLayout());
|
auto *layout = qobject_cast<TextEditor::TextDocumentLayout *>(document()->documentLayout());
|
||||||
const int documentRevision = layout->lastSaveRevision;
|
const int documentRevision = layout->lastSaveRevision;
|
||||||
|
|
||||||
@@ -483,6 +485,7 @@ bool CppEditorDocument::save(QString *errorString, const QString &fileName, bool
|
|||||||
}
|
}
|
||||||
if (editedRange.first != -1)
|
if (editedRange.first != -1)
|
||||||
formatRange(document(), indenter(), editedRange, tabSettings());
|
formatRange(document(), indenter(), editedRange, tabSettings());
|
||||||
|
cursor.endEditBlock();
|
||||||
}
|
}
|
||||||
|
|
||||||
return TextEditor::TextDocument::save(errorString, fileName, autoSave);
|
return TextEditor::TextDocument::save(errorString, fileName, autoSave);
|
||||||
|
Reference in New Issue
Block a user