From 28244a599609143774db0459920e98f70be8c6d5 Mon Sep 17 00:00:00 2001 From: Don Ho Date: Tue, 3 Dec 2024 04:07:26 +0100 Subject: [PATCH] Buffer small refactoring Close #15895 --- PowerEditor/src/ScintillaComponent/Buffer.cpp | 15 +++++++-------- 1 file changed, 7 insertions(+), 8 deletions(-) diff --git a/PowerEditor/src/ScintillaComponent/Buffer.cpp b/PowerEditor/src/ScintillaComponent/Buffer.cpp index 5633ff7cd..bf1da42f8 100644 --- a/PowerEditor/src/ScintillaComponent/Buffer.cpp +++ b/PowerEditor/src/ScintillaComponent/Buffer.cpp @@ -815,18 +815,17 @@ BufferID FileManager::loadFile(const wchar_t* filename, Document doc, int encodi if (res != 0) // res == 1 or res == -1 newBuf->_timeStamp = fileNameTimestamp; - _buffers.push_back(newBuf); - ++_nbBufs; - Buffer* buf = _buffers.at(_nbBufs - 1); - // restore the encoding (ANSI based) while opening the existing file - buf->setEncoding(-1); + newBuf->setEncoding(-1); // if not a large file, no file extension, and the language has been detected, we use the detected value - if (!newBuf->_isLargeFile && ((buf->getLangType() == L_TEXT) && (loadedFileFormat._language != L_TEXT))) - buf->setLangType(loadedFileFormat._language); + if (!newBuf->_isLargeFile && ((newBuf->getLangType() == L_TEXT) && (loadedFileFormat._language != L_TEXT))) + newBuf->setLangType(loadedFileFormat._language); - setLoadedBufferEncodingAndEol(buf, UnicodeConvertor, loadedFileFormat._encoding, loadedFileFormat._eolFormat); + setLoadedBufferEncodingAndEol(newBuf, UnicodeConvertor, loadedFileFormat._encoding, loadedFileFormat._eolFormat); + + _buffers.push_back(newBuf); + ++_nbBufs; //determine buffer properties ++_nextBufferID;