From 878b00e53f8f94e6868294252518604985bbffcd Mon Sep 17 00:00:00 2001 From: xomx Date: Wed, 26 Nov 2025 16:16:59 +0100 Subject: [PATCH] Fix corrupted file loading for Windows full UTF-8 Code page System Fix corrupted file loading for UTF-8 files bigger that the Notepad++ blockSize when using default system CP 65001. Notepad++ loads files in chunks of blockSize (128 * 1024 + 4 == 131076). For the 1st chunk, it detects the possible BOM present, but for the later chunks not. If there is the Windows Region Administrative feature "Beta: Use Unicode UTF-8 for worldwide language support" ON, Notepad++ currently fails to correctly set the file encoding for the later file-chunks loaded. The wrong logic was introduced by: 8149f72#diff-2d5c277be2799a7e43a90232d8ef9add2e788e252c8692bf9416abc69836957d Fix #17234, close #17237 --- PowerEditor/src/ScintillaComponent/Buffer.cpp | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/PowerEditor/src/ScintillaComponent/Buffer.cpp b/PowerEditor/src/ScintillaComponent/Buffer.cpp index 7f307fdb1..5e046f1a2 100644 --- a/PowerEditor/src/ScintillaComponent/Buffer.cpp +++ b/PowerEditor/src/ScintillaComponent/Buffer.cpp @@ -1976,6 +1976,7 @@ bool FileManager::loadFileData(Document doc, int64_t fileSize, const wchar_t * f size_t lenConvert = 0; //just in case conversion results in 0, but file not empty bool isFirstTime = true; int incompleteMultibyteChar = 0; + bool hasBOM = false; do { @@ -1988,9 +1989,8 @@ bool FileManager::loadFileData(Document doc, int64_t fileSize, const wchar_t * f if (lenFile == 0) break; - bool hasBOM = false; - if (isFirstTime) - { + if (isFirstTime) + { NppParameters& nppParamInst = NppParameters::getInstance(); const NppGUI& nppGui = nppParamInst.getNppGUI(); @@ -2023,8 +2023,8 @@ bool FileManager::loadFileData(Document doc, int64_t fileSize, const wchar_t * f fileFormat._language = detectLanguageFromTextBeginning((unsigned char *)data, lenFile); } - isFirstTime = false; - } + isFirstTime = false; + } if (fileFormat._encoding != -1)