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:
Ivan Donchevskii
2019-02-08 08:59:06 +01:00
parent e20a0ed580
commit f8dd6b35ec

View File

@@ -462,6 +462,8 @@ static int formatRange(QTextDocument *doc,
bool CppEditorDocument::save(QString *errorString, const QString &fileName, bool autoSave)
{
if (indenter()->formatOnSave()) {
QTextCursor cursor(document());
cursor.joinPreviousEditBlock();
auto *layout = qobject_cast<TextEditor::TextDocumentLayout *>(document()->documentLayout());
const int documentRevision = layout->lastSaveRevision;
@@ -483,6 +485,7 @@ bool CppEditorDocument::save(QString *errorString, const QString &fileName, bool
}
if (editedRange.first != -1)
formatRange(document(), indenter(), editedRange, tabSettings());
cursor.endEditBlock();
}
return TextEditor::TextDocument::save(errorString, fileName, autoSave);