Fix wrong EOL detection for big files while reloading

This commit is contained in:
Don Ho 2015-10-27 16:51:31 +01:00
parent 280ddcd493
commit 7e8218f735
2 changed files with 12 additions and 28 deletions

View File

@ -594,7 +594,7 @@ BufferID FileManager::loadFile(const TCHAR * filename, Document doc, int encodin
char data[blockSize + 8]; // +8 for incomplete multibyte char char data[blockSize + 8]; // +8 for incomplete multibyte char
EolType bkformat = EolType::unknown; EolType bkformat = EolType::unknown;
LangType detectedLang = L_TEXT; LangType detectedLang = L_TEXT;
bool res = loadFileData(doc, backupFileName ? backupFileName : fullpath, data, &UnicodeConvertor, detectedLang, encoding, &bkformat); bool res = loadFileData(doc, backupFileName ? backupFileName : fullpath, data, &UnicodeConvertor, detectedLang, encoding, bkformat);
if (res) if (res)
{ {
Buffer* newBuf = new Buffer(this, _nextBufferID, doc, DOC_REGULAR, fullpath); Buffer* newBuf = new Buffer(this, _nextBufferID, doc, DOC_REGULAR, fullpath);
@ -670,31 +670,18 @@ 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, lang, encoding, &bkformat); bool res = loadFileData(doc, buf->getFullPathName(), data, &UnicodeConvertor, lang, encoding, bkformat);
buf->_canNotify = true; buf->_canNotify = true;
if (res) if (res)
{ {
if (encoding == -1) if (encoding == -1)
{ {
NppParameters *pNppParamInst = NppParameters::getInstance();
const NewDocDefaultSettings & ndds = (pNppParamInst->getNppGUI()).getNewDocDefaultSettings(); // for ndds._format
if (nullptr != UnicodeConvertor.getNewBuf())
{
EolType format = getEOLFormatForm(UnicodeConvertor.getNewBuf(), UnicodeConvertor.getNewSize(), ndds._format);
buf->setFormat(format);
}
else{
buf->setFormat(ndds._format);
}
buf->setUnicodeMode(UnicodeConvertor.getEncoding()); buf->setUnicodeMode(UnicodeConvertor.getEncoding());
} }
else else
{ {
buf->setEncoding(encoding); buf->setEncoding(encoding);
buf->setFormat(bkformat);
buf->setUnicodeMode(uniCookie); buf->setUnicodeMode(uniCookie);
} }
} }
@ -1340,7 +1327,7 @@ LangType FileManager::detectLanguageFromTextBegining(const unsigned char *data,
return L_TEXT; return L_TEXT;
} }
inline bool FileManager::loadFileData(Document doc, const TCHAR * filename, char* data, Utf8_16_Read * unicodeConvertor, LangType & language, int & encoding, EolType* pFormat) inline bool FileManager::loadFileData(Document doc, const TCHAR * filename, char* data, Utf8_16_Read * unicodeConvertor, LangType & language, int & encoding, EolType & eolFormat)
{ {
FILE *fp = generic_fopen(filename, TEXT("rb")); FILE *fp = generic_fopen(filename, TEXT("rb"));
if (!fp) if (!fp)
@ -1484,18 +1471,15 @@ inline bool FileManager::loadFileData(Document doc, const TCHAR * filename, char
fclose(fp); fclose(fp);
// broadcast the format // broadcast the format
if (pFormat != nullptr)
{
if (format == EolType::unknown) if (format == EolType::unknown)
{ {
NppParameters *pNppParamInst = NppParameters::getInstance(); NppParameters *pNppParamInst = NppParameters::getInstance();
const NewDocDefaultSettings & ndds = (pNppParamInst->getNppGUI()).getNewDocDefaultSettings(); // for ndds._format const NewDocDefaultSettings & ndds = (pNppParamInst->getNppGUI()).getNewDocDefaultSettings(); // for ndds._format
*pFormat = ndds._format; eolFormat = ndds._format;
} }
else else
{ {
*pFormat = format; eolFormat = format;
}
} }
_pscratchTilla->execute(SCI_EMPTYUNDOBUFFER); _pscratchTilla->execute(SCI_EMPTYUNDOBUFFER);

View File

@ -111,7 +111,7 @@ public:
private: 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, LangType & language, int& encoding, EolType* pFormat = nullptr); bool loadFileData(Document doc, const TCHAR* filename, char* buffer, Utf8_16_Read* UnicodeConvertor, LangType & language, int & encoding, EolType & eolFormat);
LangType detectLanguageFromTextBegining(const unsigned char *data, unsigned int dataLen); LangType detectLanguageFromTextBegining(const unsigned char *data, unsigned int dataLen);