From f8dd6b35ec6855583b28f4f81e39192c94d0b73b Mon Sep 17 00:00:00 2001 From: Ivan Donchevskii Date: Fri, 8 Feb 2019 08:59:06 +0100 Subject: [PATCH] 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 --- src/plugins/cppeditor/cppeditordocument.cpp | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/plugins/cppeditor/cppeditordocument.cpp b/src/plugins/cppeditor/cppeditordocument.cpp index c1577424570..d058adac9ee 100644 --- a/src/plugins/cppeditor/cppeditordocument.cpp +++ b/src/plugins/cppeditor/cppeditordocument.cpp @@ -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(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);