Fix encoding not sync (on status bar) after reloading
Extracted parts of FileManager::reloadBuffer and FileManager::loadFile to a separate function, so that both exhibit the same feature level of EOL/encoding detection. reloadBuffer() used to have less logic than loadFile() and incorrectly handled UTF-8 detection when the file was ANSI Fixes #2637, fixes #2843, closes #4124
This commit is contained in:
parent
926a5f5300
commit
2c4a389f55
@ -601,31 +601,13 @@ BufferID FileManager::loadFile(const TCHAR * filename, Document doc, int encodin
|
|||||||
Buffer* buf = _buffers.at(_nbBufs - 1);
|
Buffer* buf = _buffers.at(_nbBufs - 1);
|
||||||
|
|
||||||
// restore the encoding (ANSI based) while opening the existing file
|
// restore the encoding (ANSI based) while opening the existing file
|
||||||
NppParameters *pNppParamInst = NppParameters::getInstance();
|
|
||||||
const NewDocDefaultSettings & ndds = (pNppParamInst->getNppGUI()).getNewDocDefaultSettings();
|
|
||||||
buf->setUnicodeMode(ndds._unicodeMode);
|
|
||||||
buf->setEncoding(-1);
|
buf->setEncoding(-1);
|
||||||
|
|
||||||
// if no file extension, and the language has been detected, we use the detected value
|
// if no file extension, and the language has been detected, we use the detected value
|
||||||
if ((buf->getLangType() == L_TEXT) && (detectedLang != L_TEXT))
|
if ((buf->getLangType() == L_TEXT) && (detectedLang != L_TEXT))
|
||||||
buf->setLangType(detectedLang);
|
buf->setLangType(detectedLang);
|
||||||
|
|
||||||
if (encoding == -1)
|
setLoadedBufferEncodingAndEol(buf, UnicodeConvertor, encoding, bkformat);
|
||||||
{
|
|
||||||
UniMode um = UnicodeConvertor.getEncoding();
|
|
||||||
if (um == uni7Bit)
|
|
||||||
um = (ndds._openAnsiAsUtf8) ? uniCookie : uni8Bit;
|
|
||||||
|
|
||||||
buf->setUnicodeMode(um);
|
|
||||||
}
|
|
||||||
else // encoding != -1
|
|
||||||
{
|
|
||||||
// Test if encoding is set to UTF8 w/o BOM (usually for utf8 indicator of xml or html)
|
|
||||||
buf->setEncoding((encoding == SC_CP_UTF8)?-1:encoding);
|
|
||||||
buf->setUnicodeMode(uniCookie);
|
|
||||||
}
|
|
||||||
|
|
||||||
buf->setEolFormat(bkformat);
|
|
||||||
|
|
||||||
//determine buffer properties
|
//determine buffer properties
|
||||||
++_nextBufferID;
|
++_nextBufferID;
|
||||||
@ -660,24 +642,38 @@ bool FileManager::reloadBuffer(BufferID id)
|
|||||||
|
|
||||||
if (res)
|
if (res)
|
||||||
{
|
{
|
||||||
if (encoding == -1)
|
setLoadedBufferEncodingAndEol(buf, UnicodeConvertor, encoding, bkformat);
|
||||||
{
|
|
||||||
buf->setUnicodeMode(UnicodeConvertor.getEncoding());
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
buf->setEncoding(encoding);
|
|
||||||
buf->setUnicodeMode(uniCookie);
|
|
||||||
}
|
|
||||||
|
|
||||||
// Since the buffer will be reloaded from the disk, EOL might have been changed
|
|
||||||
if (bkformat != EolType::unknown)
|
|
||||||
buf->setEolFormat(bkformat);
|
|
||||||
}
|
}
|
||||||
return res;
|
return res;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void FileManager::setLoadedBufferEncodingAndEol(Buffer* buf, const Utf8_16_Read& UnicodeConvertor, int encoding, EolType bkformat)
|
||||||
|
{
|
||||||
|
if (encoding == -1)
|
||||||
|
{
|
||||||
|
NppParameters *pNppParamInst = NppParameters::getInstance();
|
||||||
|
const NewDocDefaultSettings & ndds = (pNppParamInst->getNppGUI()).getNewDocDefaultSettings();
|
||||||
|
|
||||||
|
UniMode um = UnicodeConvertor.getEncoding();
|
||||||
|
if (um == uni7Bit)
|
||||||
|
um = (ndds._openAnsiAsUtf8) ? uniCookie : uni8Bit;
|
||||||
|
|
||||||
|
buf->setUnicodeMode(um);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
// Test if encoding is set to UTF8 w/o BOM (usually for utf8 indicator of xml or html)
|
||||||
|
buf->setEncoding((encoding == SC_CP_UTF8)?-1:encoding);
|
||||||
|
buf->setUnicodeMode(uniCookie);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Since the buffer will be reloaded from the disk, EOL might have been changed
|
||||||
|
if (bkformat != EolType::unknown)
|
||||||
|
buf->setEolFormat(bkformat);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
bool FileManager::reloadBufferDeferred(BufferID id)
|
bool FileManager::reloadBufferDeferred(BufferID id)
|
||||||
{
|
{
|
||||||
Buffer* buf = getBufferByID(id);
|
Buffer* buf = getBufferByID(id);
|
||||||
|
@ -97,6 +97,7 @@ public:
|
|||||||
BufferID getBufferFromName(const TCHAR * name);
|
BufferID getBufferFromName(const TCHAR * name);
|
||||||
BufferID getBufferFromDocument(Document doc);
|
BufferID getBufferFromDocument(Document doc);
|
||||||
|
|
||||||
|
void setLoadedBufferEncodingAndEol(Buffer* buf, const Utf8_16_Read& UnicodeConvertor, int encoding, EolType bkformat);
|
||||||
bool reloadBuffer(BufferID id);
|
bool reloadBuffer(BufferID id);
|
||||||
bool reloadBufferDeferred(BufferID id);
|
bool reloadBufferDeferred(BufferID id);
|
||||||
bool saveBuffer(BufferID id, const TCHAR* filename, bool isCopy = false, generic_string * error_msg = NULL);
|
bool saveBuffer(BufferID id, const TCHAR* filename, bool isCopy = false, generic_string * error_msg = NULL);
|
||||||
|
Loading…
Reference in New Issue
Block a user