@@ -1496,9 +1496,14 @@ bool Note::storeNoteTextFileToDisk(bool ¤tNoteTextChanged,
14961496 // Check if the file was modified externally by comparing checksums
14971497 if (enableNoteChecksumChecks && !ignoreAllExternalModifications && fileExists () &&
14981498 !_fileChecksum.isEmpty ()) {
1499- // Read the current file content
1499+ // Read the current file content using the same flags as when writing
1500+ // to ensure newline handling is consistent (important on Windows)
15001501 QFile checkFile (fullNoteFilePath ());
1501- if (checkFile.open (QIODevice::ReadOnly)) {
1502+ QFile::OpenMode checkFlags = QIODevice::ReadOnly;
1503+ if (!useUNIXNewline) {
1504+ checkFlags |= QIODevice::Text;
1505+ }
1506+ if (checkFile.open (checkFlags)) {
15021507 QTextStream checkIn (&checkFile);
15031508#if QT_VERSION < QT_VERSION_CHECK(6, 0, 0)
15041509 checkIn.setCodec (" UTF-8" );
@@ -1943,7 +1948,15 @@ bool Note::updateNoteTextFromDisk() {
19431948
19441949 QFile file (fullNoteFilePath ());
19451950
1946- if (!file.open (QIODevice::ReadOnly)) {
1951+ // Use the same flags as when writing to ensure consistent newline handling
1952+ const SettingsService settings;
1953+ const bool useUNIXNewline = settings.value (QStringLiteral (" useUNIXNewline" )).toBool ();
1954+ QFile::OpenMode flags = QIODevice::ReadOnly;
1955+ if (!useUNIXNewline) {
1956+ flags |= QIODevice::Text;
1957+ }
1958+
1959+ if (!file.open (flags)) {
19471960 qDebug () << __func__ << " - 'file': " << file.fileName ();
19481961 qDebug () << __func__ << " - " << file.errorString ();
19491962 return false ;
@@ -1997,7 +2010,7 @@ bool Note::updateNoteTextFromDisk() {
19972010 }
19982011
19992012 // Calculate and store the checksum of the loaded text (if enabled)
2000- const SettingsService settings;
2013+ // settings was already retrieved at the beginning of the function
20012014 const bool enableNoteChecksumChecks =
20022015 settings.value (QStringLiteral (" enableNoteChecksumChecks" ), false ).toBool ();
20032016 if (enableNoteChecksumChecks) {
@@ -2327,7 +2340,15 @@ QString Note::detectNewlineCharacters() {
23272340}
23282341
23292342void Note::createFromFile (QFile &file, int noteSubFolderId, bool withNoteNameHook) {
2330- if (file.open (QIODevice::ReadOnly)) {
2343+ // Use the same flags as when writing to ensure consistent newline handling
2344+ const SettingsService settings;
2345+ const bool useUNIXNewline = settings.value (QStringLiteral (" useUNIXNewline" )).toBool ();
2346+ QFile::OpenMode flags = QIODevice::ReadOnly;
2347+ if (!useUNIXNewline) {
2348+ flags |= QIODevice::Text;
2349+ }
2350+
2351+ if (file.open (flags)) {
23312352 QFileInfo fileInfo;
23322353 fileInfo.setFile (file);
23332354
@@ -2375,7 +2396,7 @@ void Note::createFromFile(QFile &file, int noteSubFolderId, bool withNoteNameHoo
23752396 this ->_fileLastModified = fileInfo.lastModified ();
23762397
23772398 // Calculate the checksum before storing (if enabled)
2378- const SettingsService settings;
2399+ // settings was already retrieved above
23792400 const bool enableNoteChecksumChecks =
23802401 settings.value (QStringLiteral (" enableNoteChecksumChecks" ), false ).toBool ();
23812402 if (enableNoteChecksumChecks) {
0 commit comments