aboutsummaryrefslogtreecommitdiffstats
path: root/src/plugins/cppeditor/cppeditordocument.cpp
diff options
context:
space:
mode:
authorIvan Donchevskii <ivan.donchevskii@qt.io>2019-04-02 09:48:30 +0200
committerIvan Donchevskii <ivan.donchevskii@qt.io>2019-04-02 11:33:30 +0000
commit6f745e0a4def20176f7ae5d1609cabe847de466f (patch)
treee47afe69f461e43ec423cde7e3ab3a9da354d28b /src/plugins/cppeditor/cppeditordocument.cpp
parent01a528c77a3aee7cdd264f9f71d9b2d30a9c775a (diff)
ClangFormat: Do not remove whitespace twice
Previously the built-in engine was responsible for clearing the extra whitespace. When ClangFormat plugin is active and "Format edited code on file save" is selected it clears the unnecessary whitespace on it's own and we don't need to adjust the whitespace the second time. Fixes: QTCREATORBUG-22239 Change-Id: I309f51c51aca8ab85b5cfb7809923b59a912b4e0 Reviewed-by: Marco Bubke <marco.bubke@qt.io>
Diffstat (limited to 'src/plugins/cppeditor/cppeditordocument.cpp')
-rw-r--r--src/plugins/cppeditor/cppeditordocument.cpp10
1 files changed, 10 insertions, 0 deletions
diff --git a/src/plugins/cppeditor/cppeditordocument.cpp b/src/plugins/cppeditor/cppeditordocument.cpp
index 6da4ac43fc..85c10e8f0c 100644
--- a/src/plugins/cppeditor/cppeditordocument.cpp
+++ b/src/plugins/cppeditor/cppeditordocument.cpp
@@ -44,10 +44,12 @@
#include <projectexplorer/session.h>
#include <texteditor/icodestylepreferencesfactory.h>
+#include <texteditor/storagesettings.h>
#include <texteditor/textdocumentlayout.h>
#include <texteditor/texteditorsettings.h>
#include <coreplugin/editormanager/editormanager.h>
+#include <utils/executeondestruction.h>
#include <utils/mimetypes/mimedatabase.h>
#include <utils/qtcassert.h>
#include <utils/runextensions.h>
@@ -448,6 +450,8 @@ TextEditor::TabSettings CppEditorDocument::tabSettings() const
bool CppEditorDocument::save(QString *errorString, const QString &fileName, bool autoSave)
{
+ Utils::ExecuteOnDestruction resetSettingsOnScopeExit;
+
if (indenter()->formatOnSave() && !autoSave) {
auto *layout = qobject_cast<TextEditor::TextDocumentLayout *>(document()->documentLayout());
const int documentRevision = layout->lastSaveRevision;
@@ -479,6 +483,12 @@ bool CppEditorDocument::save(QString *errorString, const QString &fileName, bool
indenter()->format(editedRanges);
cursor.endEditBlock();
}
+
+ TextEditor::StorageSettings settings = storageSettings();
+ resetSettingsOnScopeExit.reset(
+ [this, defaultSettings = settings]() { setStorageSettings(defaultSettings); });
+ settings.m_cleanWhitespace = false;
+ setStorageSettings(settings);
}
return TextEditor::TextDocument::save(errorString, fileName, autoSave);