File tree Expand file tree Collapse file tree 2 files changed +8
-3
lines changed Expand file tree Collapse file tree 2 files changed +8
-3
lines changed Original file line number Diff line number Diff line change @@ -65,6 +65,7 @@ void TextEditor::clear()
65
65
66
66
m_filename.clear ();
67
67
m_encoding.clear ();
68
+ m_needsBOM = false ;
68
69
setPlainText (" " );
69
70
dirty (false );
70
71
document ()->setModified (false );
@@ -80,7 +81,7 @@ bool TextEditor::load(const QString& filename)
80
81
81
82
m_filename = filename;
82
83
83
- const QString s = MOBase::readFileText (filename, &m_encoding);
84
+ const QString s = MOBase::readFileText (filename, &m_encoding, &m_needsBOM );
84
85
85
86
setPlainText (s);
86
87
document ()->setModified (false );
@@ -106,10 +107,13 @@ bool TextEditor::save()
106
107
file.open (QIODevice::WriteOnly);
107
108
file.resize (0 );
108
109
109
- auto codec = QStringConverter::encodingForName (m_encoding.toLocal8Bit ());
110
+ auto codec = QStringConverter::encodingForName (m_encoding.toUtf8 ());
110
111
if (!codec.has_value ())
111
112
return false ;
112
- QStringEncoder encoder (codec.value ());
113
+ QStringConverter::Flags flags = QStringEncoder::Flag::Default;
114
+ if (m_needsBOM)
115
+ flags |= QStringConverter::Flag::WriteBom;
116
+ QStringEncoder encoder (codec.value (), flags);
113
117
114
118
QString data = toPlainText ().replace (" \n " , " \r\n " );
115
119
Original file line number Diff line number Diff line change @@ -130,6 +130,7 @@ class TextEditor : public QPlainTextEdit
130
130
QColor m_highlightBackground;
131
131
QString m_filename;
132
132
QString m_encoding;
133
+ bool m_needsBOM;
133
134
bool m_dirty;
134
135
bool m_loading;
135
136
You can’t perform that action at this time.
0 commit comments