From 5299eb5bec3f51b49cfddf3605db6e981f8cd466 Mon Sep 17 00:00:00 2001 From: David Schulz Date: Mon, 7 Sep 2020 10:52:54 +0200 Subject: TextEditor: Fix clean whitespace action This is a partial revert of: e7f784ca7393bddb60cbb111d3bdb7cd0e6d122e Fixes: QTCREATORBUG-24565 Change-Id: Iffa149e0f97c315355f211f6ae3856fad08f4f3d Reviewed-by: Christian Stenger --- src/plugins/texteditor/textdocument.cpp | 22 ++++++++++++---------- src/plugins/texteditor/textdocument.h | 2 +- 2 files changed, 13 insertions(+), 11 deletions(-) (limited to 'src') diff --git a/src/plugins/texteditor/textdocument.cpp b/src/plugins/texteditor/textdocument.cpp index ee8d95736c3..55c4592154a 100644 --- a/src/plugins/texteditor/textdocument.cpp +++ b/src/plugins/texteditor/textdocument.cpp @@ -622,8 +622,11 @@ bool TextDocument::save(QString *errorString, const QString &saveFileName, bool cursor.beginEditBlock(); cursor.movePosition(QTextCursor::Start); - if (d->m_storageSettings.m_cleanWhitespace) - cleanWhitespace(cursor, d->m_storageSettings); + if (d->m_storageSettings.m_cleanWhitespace) { + cleanWhitespace(cursor, + d->m_storageSettings.m_inEntireDocument, + d->m_storageSettings.m_cleanIndentation); + } if (d->m_storageSettings.m_addFinalNewLine) ensureFinalNewLine(cursor); cursor.endEditBlock(); @@ -885,7 +888,7 @@ void TextDocument::cleanWhitespace(const QTextCursor &cursor) copyCursor.setVisualNavigation(false); copyCursor.beginEditBlock(); - cleanWhitespace(copyCursor, d->m_storageSettings); + cleanWhitespace(copyCursor, true, true); if (!hasSelection) ensureFinalNewLine(copyCursor); @@ -893,11 +896,9 @@ void TextDocument::cleanWhitespace(const QTextCursor &cursor) copyCursor.endEditBlock(); } -void TextDocument::cleanWhitespace(QTextCursor &cursor, const StorageSettings &storageSettings) +void TextDocument::cleanWhitespace(QTextCursor &cursor, bool inEntireDocument, + bool cleanIndentation) { - if (!d->m_storageSettings.m_cleanWhitespace) - return; - const QString fileName(filePath().fileName()); auto documentLayout = qobject_cast(d->m_document.documentLayout()); @@ -910,8 +911,9 @@ void TextDocument::cleanWhitespace(QTextCursor &cursor, const StorageSettings &s QVector blocks; while (block.isValid() && block != end) { - if (storageSettings.m_inEntireDocument || block.revision() != documentLayout->lastSaveRevision) + if (inEntireDocument || block.revision() != documentLayout->lastSaveRevision) { blocks.append(block); + } block = block.next(); } if (blocks.isEmpty()) @@ -924,11 +926,11 @@ void TextDocument::cleanWhitespace(QTextCursor &cursor, const StorageSettings &s foreach (block, blocks) { QString blockText = block.text(); - if (storageSettings.removeTrailingWhitespace(fileName)) + if (d->m_storageSettings.removeTrailingWhitespace(fileName)) currentTabSettings.removeTrailingWhitespace(cursor, block); const int indent = indentations[block.blockNumber()]; - if (storageSettings.m_cleanIndentation && !currentTabSettings.isIndentationClean(block, indent)) { + if (cleanIndentation && !currentTabSettings.isIndentationClean(block, indent)) { cursor.setPosition(block.position()); int firstNonSpace = currentTabSettings.firstNonSpace(blockText); if (firstNonSpace == blockText.length()) { diff --git a/src/plugins/texteditor/textdocument.h b/src/plugins/texteditor/textdocument.h index d91390869c6..b01ea25574a 100644 --- a/src/plugins/texteditor/textdocument.h +++ b/src/plugins/texteditor/textdocument.h @@ -170,7 +170,7 @@ protected: private: OpenResult openImpl(QString *errorString, const QString &fileName, const QString &realFileName, bool reload); - void cleanWhitespace(QTextCursor &cursor, const StorageSettings &storageSettings); + void cleanWhitespace(QTextCursor &cursor, bool inEntireDocument, bool cleanIndentation); void ensureFinalNewLine(QTextCursor &cursor); void modificationChanged(bool modified); void updateLayout() const; -- cgit v1.2.3