aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDavid Schulz <david.schulz@qt.io>2020-09-07 10:52:54 +0200
committerDavid Schulz <david.schulz@qt.io>2020-09-08 04:23:14 +0000
commit5299eb5bec3f51b49cfddf3605db6e981f8cd466 (patch)
tree24d3698245a842128f71d8537d03f844ed59a94e
parentd64ebc0f8b3911bb0f292059150cf1c35df5d417 (diff)
TextEditor: Fix clean whitespace action
This is a partial revert of: e7f784ca7393bddb60cbb111d3bdb7cd0e6d122e Fixes: QTCREATORBUG-24565 Change-Id: Iffa149e0f97c315355f211f6ae3856fad08f4f3d Reviewed-by: Christian Stenger <christian.stenger@qt.io>
-rw-r--r--src/plugins/texteditor/textdocument.cpp22
-rw-r--r--src/plugins/texteditor/textdocument.h2
2 files changed, 13 insertions, 11 deletions
diff --git a/src/plugins/texteditor/textdocument.cpp b/src/plugins/texteditor/textdocument.cpp
index ee8d95736c..55c4592154 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<TextDocumentLayout*>(d->m_document.documentLayout());
@@ -910,8 +911,9 @@ void TextDocument::cleanWhitespace(QTextCursor &cursor, const StorageSettings &s
QVector<QTextBlock> 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 d91390869c..b01ea25574 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;