Preserve non-breaking space on saving text files

Use toRawText instead of toPlainText, see QTBUG-56538.

Fixes: QTCREATORBUG-22052
Change-Id: I01eaa57d2d1afed12e45ee88568667b161fd89fd
Reviewed-by: David Schulz <david.schulz@qt.io>
This commit is contained in:
Eike Ziller
2019-03-04 10:36:25 +01:00
parent 10a04ce40d
commit c6b6a6a077
5 changed files with 6 additions and 6 deletions

View File

@@ -126,7 +126,7 @@ bool FixitsRefactoringFile::apply()
QString error; QString error;
for (auto it = m_documents.begin(); it != m_documents.end(); ++it) { for (auto it = m_documents.begin(); it != m_documents.end(); ++it) {
if (!m_textFileFormat.writeFile(it.key(), it.value()->toPlainText(), &error)) { if (!m_textFileFormat.writeFile(it.key(), it.value()->toRawText(), &error)) {
qCDebug(fixitsLog) << "ERROR: Could not write file" << it.key() << ":" << error; qCDebug(fixitsLog) << "ERROR: Could not write file" << it.key() << ":" << error;
return false; // Error writing file return false; // Error writing file
} }

View File

@@ -117,7 +117,7 @@ bool JsonWizardGenerator::formatFile(const JsonWizard *wizard, GeneratedFile *fi
block = block.next(); block = block.next();
} }
} }
file->setContents(doc.toPlainText()); file->setContents(doc.toRawText());
return true; return true;
} }

View File

@@ -277,7 +277,7 @@ void ProjectFileWizardExtension::applyCodeStyle(GeneratedFile *file) const
block = block.next(); block = block.next();
} }
} }
file->setContents(doc.toPlainText()); file->setContents(doc.toRawText());
} }
} // namespace Internal } // namespace Internal

View File

@@ -97,7 +97,7 @@ bool RefactoringChanges::createFile(const QString &fileName, const QString &cont
TextFileFormat format; TextFileFormat format;
format.codec = EditorManager::defaultTextCodec(); format.codec = EditorManager::defaultTextCodec();
QString error; QString error;
bool saveOk = format.writeFile(fileName, document->toPlainText(), &error); bool saveOk = format.writeFile(fileName, document->toRawText(), &error);
delete document; delete document;
if (!saveOk) if (!saveOk)
return false; return false;
@@ -367,7 +367,7 @@ bool RefactoringFile::apply()
QString error; QString error;
// suppress "file has changed" warnings if the file is open in a read-only editor // suppress "file has changed" warnings if the file is open in a read-only editor
Core::FileChangeBlocker block(m_fileName); Core::FileChangeBlocker block(m_fileName);
if (!m_textFileFormat.writeFile(m_fileName, doc->toPlainText(), &error)) { if (!m_textFileFormat.writeFile(m_fileName, doc->toRawText(), &error)) {
qWarning() << "Could not apply changes to" << m_fileName << ". Error: " << error; qWarning() << "Could not apply changes to" << m_fileName << ". Error: " << error;
result = false; result = false;
} }

View File

@@ -569,7 +569,7 @@ bool TextDocument::save(QString *errorString, const QString &saveFileName, bool
} }
} }
const bool ok = write(fName, saveFormat, d->m_document.toPlainText(), errorString); const bool ok = write(fName, saveFormat, d->m_document.toRawText(), errorString);
// restore text cursor and scroll bar positions // restore text cursor and scroll bar positions
if (autoSave && undos < d->m_document.availableUndoSteps()) { if (autoSave && undos < d->m_document.availableUndoSteps()) {