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>
This commit is contained in:
Ivan Donchevskii
2019-04-02 09:48:30 +02:00
parent 01a528c77a
commit 6f745e0a4d

View File

@@ -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);