forked from qt-creator/qt-creator
Preserve original line ending in find->replace
Task-number: QTCREATORBUG-5581 Change-Id: Id1aae0d27d474ca051696032ab3b36e7783b766f Reviewed-on: http://codereview.qt.nokia.com/2102 Reviewed-by: Qt Sanity Bot <qt_sanity_bot@ovi.com> Reviewed-by: Eike Ziller <eike.ziller@nokia.com>
This commit is contained in:
committed by
Leandro T. C. Melo
parent
3bd37a7160
commit
945b5f9a03
@@ -351,17 +351,27 @@ QStringList BaseFileFind::replaceAll(const QString &text,
|
||||
} else {
|
||||
Utils::FileReader reader;
|
||||
if (reader.fetch(fileName, Core::ICore::instance()->mainWindow())) {
|
||||
// Keep track of line ending since QTextDocument is '\n' based.
|
||||
bool convertLineEnding = false;
|
||||
const QByteArray &data = reader.data();
|
||||
const int lf = data.indexOf('\n');
|
||||
if (lf > 0 && data.at(lf - 1) == '\r')
|
||||
convertLineEnding = true;
|
||||
|
||||
QTextDocument doc;
|
||||
// ### set the encoding
|
||||
doc.setPlainText(QString::fromLocal8Bit(reader.data()));
|
||||
|
||||
doc.setPlainText(QString::fromLocal8Bit(data));
|
||||
applyChanges(&doc, text, changeItems);
|
||||
QString plainText = doc.toPlainText();
|
||||
|
||||
if (convertLineEnding)
|
||||
plainText.replace(QLatin1Char('\n'), QLatin1String("\r\n"));
|
||||
|
||||
Utils::FileSaver saver(fileName);
|
||||
if (!saver.hasError()) {
|
||||
QTextStream stream(saver.file());
|
||||
// ### set the encoding
|
||||
stream << doc.toPlainText();
|
||||
stream << plainText;
|
||||
saver.setResult(&stream);
|
||||
}
|
||||
saver.finalize(Core::ICore::instance()->mainWindow());
|
||||
|
||||
Reference in New Issue
Block a user