Allow undo after file reload and don't purge undo buffer

Close #5273, fix #5141
This commit is contained in:
Don HO 2019-03-28 19:59:02 +01:00
parent 017e09a23d
commit 198cf90c16
No known key found for this signature in database
GPG Key ID: 6C429F1D8D84F46E
2 changed files with 10 additions and 4 deletions

View File

@ -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. 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 // 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; buf->_canNotify = true;
if (res) if (res)
@ -1261,7 +1261,7 @@ LangType FileManager::detectLanguageFromTextBegining(const unsigned char *data,
return L_TEXT; 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")); FILE *fp = generic_fopen(filename, TEXT("rb"));
if (not fp) if (not fp)
@ -1295,6 +1295,12 @@ bool FileManager::loadFileData(Document doc, const TCHAR * filename, char* data,
{ {
_pscratchTilla->execute(SCI_SETREADONLY, false); _pscratchTilla->execute(SCI_SETREADONLY, false);
} }
if (!purgeUndoBuffer)
{
_pscratchTilla->execute(SCI_BEGINUNDOACTION);
}
_pscratchTilla->execute(SCI_CLEARALL); _pscratchTilla->execute(SCI_CLEARALL);
@ -1427,7 +1433,7 @@ bool FileManager::loadFileData(Document doc, const TCHAR * filename, char* data,
fileFormat._eolFormat = format; fileFormat._eolFormat = format;
} }
_pscratchTilla->execute(SCI_EMPTYUNDOBUFFER); _pscratchTilla->execute(purgeUndoBuffer ? SCI_EMPTYUNDOBUFFER : SCI_ENDUNDOACTION);
_pscratchTilla->execute(SCI_SETSAVEPOINT); _pscratchTilla->execute(SCI_SETSAVEPOINT);
if (ro) if (ro)

View File

@ -122,7 +122,7 @@ private:
}; };
~FileManager(); ~FileManager();
int detectCodepage(char* buf, size_t len); 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); LangType detectLanguageFromTextBegining(const unsigned char *data, size_t dataLen);