diff --git a/PowerEditor/src/ScitillaComponent/Buffer.cpp b/PowerEditor/src/ScitillaComponent/Buffer.cpp index 742bdd35..81ff7f17 100644 --- a/PowerEditor/src/ScitillaComponent/Buffer.cpp +++ b/PowerEditor/src/ScitillaComponent/Buffer.cpp @@ -674,7 +674,7 @@ bool FileManager::reloadBuffer(BufferID id) buf->setLoadedDirty(false); // Since the buffer will be reloaded from the disk, and it will be clean (not dirty), we can set _isLoadedDirty false safetly. // Set _isLoadedDirty false before calling "_pscratchTilla->execute(SCI_CLEARALL);" in loadFileData() to avoid setDirty in SCN_SAVEPOINTREACHED / SCN_SAVEPOINTLEFT - bool res = loadFileData(doc, buf->getFullPathName(), data, &UnicodeConvertor, loadedFileFormat); + bool res = loadFileData(doc, buf->getFullPathName(), data, &UnicodeConvertor, loadedFileFormat, false); buf->_canNotify = true; if (res) @@ -1261,7 +1261,7 @@ LangType FileManager::detectLanguageFromTextBegining(const unsigned char *data, return L_TEXT; } -bool FileManager::loadFileData(Document doc, const TCHAR * filename, char* data, Utf8_16_Read * unicodeConvertor, LoadedFileFormat& fileFormat) +bool FileManager::loadFileData(Document doc, const TCHAR * filename, char* data, Utf8_16_Read * unicodeConvertor, LoadedFileFormat& fileFormat, bool purgeUndoBuffer) { FILE *fp = generic_fopen(filename, TEXT("rb")); if (not fp) @@ -1295,6 +1295,12 @@ bool FileManager::loadFileData(Document doc, const TCHAR * filename, char* data, { _pscratchTilla->execute(SCI_SETREADONLY, false); } + + if (!purgeUndoBuffer) + { + _pscratchTilla->execute(SCI_BEGINUNDOACTION); + } + _pscratchTilla->execute(SCI_CLEARALL); @@ -1427,7 +1433,7 @@ bool FileManager::loadFileData(Document doc, const TCHAR * filename, char* data, fileFormat._eolFormat = format; } - _pscratchTilla->execute(SCI_EMPTYUNDOBUFFER); + _pscratchTilla->execute(purgeUndoBuffer ? SCI_EMPTYUNDOBUFFER : SCI_ENDUNDOACTION); _pscratchTilla->execute(SCI_SETSAVEPOINT); if (ro) diff --git a/PowerEditor/src/ScitillaComponent/Buffer.h b/PowerEditor/src/ScitillaComponent/Buffer.h index 784f155b..59ac4873 100644 --- a/PowerEditor/src/ScitillaComponent/Buffer.h +++ b/PowerEditor/src/ScitillaComponent/Buffer.h @@ -122,7 +122,7 @@ private: }; ~FileManager(); int detectCodepage(char* buf, size_t len); - bool loadFileData(Document doc, const TCHAR* filename, char* buffer, Utf8_16_Read* UnicodeConvertor, LoadedFileFormat& fileFormat); + bool loadFileData(Document doc, const TCHAR* filename, char* buffer, Utf8_16_Read* UnicodeConvertor, LoadedFileFormat& fileFormat, bool purgeUndoBuffer = true); LangType detectLanguageFromTextBegining(const unsigned char *data, size_t dataLen);