mirror of
https://github.com/notepad-plus-plus/notepad-plus-plus.git
synced 2025-07-27 07:44:24 +02:00
Fix switching different languages regression
This regression was introduced by de9ffd2. Fix #16309, close #16312
This commit is contained in:
parent
d3563cafac
commit
39d9525845
@ -4650,10 +4650,6 @@ void Notepad_plus::loadBufferIntoView(BufferID id, int whichOne, bool dontClose)
|
|||||||
{
|
{
|
||||||
idToClose = BUFFER_INVALID;
|
idToClose = BUFFER_INVALID;
|
||||||
}
|
}
|
||||||
else
|
|
||||||
{
|
|
||||||
buf->setLastLangType(-1); // When replacing the "new" tab with an opened file, the last used language should be reset to its initial value so that the language can be reloaded later in the activateBuffer() function.
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
MainFileManager.addBufferReference(id, viewToOpen);
|
MainFileManager.addBufferReference(id, viewToOpen);
|
||||||
|
@ -3720,7 +3720,6 @@ void Notepad_plus::command(int id)
|
|||||||
// Manually set language, don't change language even file extension changes.
|
// Manually set language, don't change language even file extension changes.
|
||||||
Buffer *buffer = _pEditView->getCurrentBuffer();
|
Buffer *buffer = _pEditView->getCurrentBuffer();
|
||||||
buffer->langHasBeenSetFromMenu();
|
buffer->langHasBeenSetFromMenu();
|
||||||
buffer->setLastLangType(static_cast<int>(lang));
|
|
||||||
|
|
||||||
if (_pDocMap)
|
if (_pDocMap)
|
||||||
{
|
{
|
||||||
|
@ -217,10 +217,6 @@ public:
|
|||||||
|
|
||||||
void setLangType(LangType lang, const wchar_t * userLangName = L"");
|
void setLangType(LangType lang, const wchar_t * userLangName = L"");
|
||||||
|
|
||||||
int getLastLangType() const { return _lastLangType; }
|
|
||||||
|
|
||||||
void setLastLangType(int val) { _lastLangType = val; }
|
|
||||||
|
|
||||||
UniMode getUnicodeMode() const { return _unicodeMode; }
|
UniMode getUnicodeMode() const { return _unicodeMode; }
|
||||||
|
|
||||||
void setUnicodeMode(UniMode mode);
|
void setUnicodeMode(UniMode mode);
|
||||||
@ -393,7 +389,6 @@ private:
|
|||||||
//document properties
|
//document properties
|
||||||
Document _doc; //invariable
|
Document _doc; //invariable
|
||||||
LangType _lang = L_TEXT;
|
LangType _lang = L_TEXT;
|
||||||
int _lastLangType = -1;
|
|
||||||
std::wstring _userLangExt; // it's useful if only (_lang == L_USER)
|
std::wstring _userLangExt; // it's useful if only (_lang == L_USER)
|
||||||
bool _isDirty = false;
|
bool _isDirty = false;
|
||||||
EolType _eolFormat = EolType::osdefault;
|
EolType _eolFormat = EolType::osdefault;
|
||||||
|
@ -2133,16 +2133,6 @@ void ScintillaEditView::defineDocType(LangType typeDoc)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Document ScintillaEditView::getBlankDocument()
|
|
||||||
{
|
|
||||||
if (!_blankDocument)
|
|
||||||
{
|
|
||||||
_blankDocument = static_cast<Document>(execute(SCI_CREATEDOCUMENT, 0, SC_DOCUMENTOPTION_TEXT_LARGE));
|
|
||||||
execute(SCI_ADDREFDOCUMENT, 0, _blankDocument);
|
|
||||||
}
|
|
||||||
return _blankDocument;
|
|
||||||
}
|
|
||||||
|
|
||||||
BufferID ScintillaEditView::attachDefaultDoc()
|
BufferID ScintillaEditView::attachDefaultDoc()
|
||||||
{
|
{
|
||||||
// get the doc pointer attached (by default) on the view Scintilla
|
// get the doc pointer attached (by default) on the view Scintilla
|
||||||
@ -2309,57 +2299,19 @@ void ScintillaEditView::activateBuffer(BufferID buffer, bool force)
|
|||||||
// put the state into the future ex buffer
|
// put the state into the future ex buffer
|
||||||
_currentBuffer->setHeaderLineState(lineStateVector, this);
|
_currentBuffer->setHeaderLineState(lineStateVector, this);
|
||||||
|
|
||||||
_prevBuffer = _currentBuffer;
|
|
||||||
|
|
||||||
_currentBufferID = buffer; //the magical switch happens here
|
_currentBufferID = buffer; //the magical switch happens here
|
||||||
_currentBuffer = newBuf;
|
_currentBuffer = newBuf;
|
||||||
|
|
||||||
const bool isSameLangType = (_prevBuffer != nullptr) && (_prevBuffer->getLangType() == _currentBuffer->getLangType()) &&
|
|
||||||
(_currentBuffer->getLangType() != L_USER || wcscmp(_prevBuffer->getUserDefineLangName(), _currentBuffer->getUserDefineLangName()) == 0);
|
|
||||||
|
|
||||||
const int currentLangInt = static_cast<int>(_currentBuffer->getLangType());
|
|
||||||
const bool isFirstActiveBuffer = (_currentBuffer->getLastLangType() != currentLangInt);
|
|
||||||
|
|
||||||
unsigned long MODEVENTMASK_ON = NppParameters::getInstance().getScintillaModEventMask();
|
unsigned long MODEVENTMASK_ON = NppParameters::getInstance().getScintillaModEventMask();
|
||||||
if (isFirstActiveBuffer) // Entering the tab for the 1st time
|
|
||||||
{
|
|
||||||
// change the doc, this operation will decrease
|
|
||||||
// the ref count of old current doc and increase the one of the new doc. FileManager should manage the rest
|
|
||||||
// Note that the actual reference in the Buffer itself is NOT decreased, Notepad_plus does that if neccessary
|
|
||||||
execute(SCI_SETMODEVENTMASK, MODEVENTMASK_OFF);
|
|
||||||
execute(SCI_SETDOCPOINTER, 0, _currentBuffer->getDocument());
|
|
||||||
execute(SCI_SETMODEVENTMASK, MODEVENTMASK_ON);
|
|
||||||
|
|
||||||
// Due to execute(SCI_CLEARDOCUMENTSTYLE); in defineDocType() function
|
// change the doc, this operation will decrease
|
||||||
// defineDocType() function should be called here, but not be after the fold info loop
|
// the ref count of old current doc and increase the one of the new doc. FileManager should manage the rest
|
||||||
defineDocType(_currentBuffer->getLangType());
|
// Note that the actual reference in the Buffer itself is NOT decreased, Notepad_plus does that if neccessary
|
||||||
}
|
execute(SCI_SETMODEVENTMASK, MODEVENTMASK_OFF);
|
||||||
else if (isSameLangType) // After the 2nd entering with the same language type
|
execute(SCI_SETDOCPOINTER, 0, _currentBuffer->getDocument());
|
||||||
{
|
execute(SCI_SETMODEVENTMASK, MODEVENTMASK_ON);
|
||||||
// No need to call defineDocType() since it's the same language type
|
|
||||||
execute(SCI_SETMODEVENTMASK, MODEVENTMASK_OFF);
|
|
||||||
execute(SCI_SETDOCPOINTER, 0, _currentBuffer->getDocument());
|
|
||||||
execute(SCI_SETMODEVENTMASK, MODEVENTMASK_ON);
|
|
||||||
|
|
||||||
if (force)
|
defineDocType(_currentBuffer->getLangType());
|
||||||
defineDocType(_currentBuffer->getLangType());
|
|
||||||
}
|
|
||||||
else // Entering the tab for the 2nd or more times, with the different language type
|
|
||||||
{
|
|
||||||
// In order to improve the performance of switch-in on the 2nd or more times for the large files,
|
|
||||||
// a blank document is used for accelerate defineDocType() call.
|
|
||||||
execute(SCI_SETMODEVENTMASK, MODEVENTMASK_OFF);
|
|
||||||
execute(SCI_SETDOCPOINTER, 0, getBlankDocument());
|
|
||||||
execute(SCI_SETMODEVENTMASK, MODEVENTMASK_ON);
|
|
||||||
|
|
||||||
defineDocType(_currentBuffer->getLangType());
|
|
||||||
|
|
||||||
execute(SCI_SETMODEVENTMASK, MODEVENTMASK_OFF);
|
|
||||||
execute(SCI_SETDOCPOINTER, 0, _currentBuffer->getDocument());
|
|
||||||
execute(SCI_SETMODEVENTMASK, MODEVENTMASK_ON);
|
|
||||||
}
|
|
||||||
|
|
||||||
_currentBuffer->setLastLangType(currentLangInt);
|
|
||||||
|
|
||||||
setWordChars();
|
setWordChars();
|
||||||
maintainStateForNpc();
|
maintainStateForNpc();
|
||||||
|
@ -432,11 +432,6 @@ public:
|
|||||||
|
|
||||||
virtual void destroy()
|
virtual void destroy()
|
||||||
{
|
{
|
||||||
if (_blankDocument != 0)
|
|
||||||
{
|
|
||||||
execute(SCI_RELEASEDOCUMENT, 0, _blankDocument);
|
|
||||||
_blankDocument = 0;
|
|
||||||
}
|
|
||||||
::DestroyWindow(_hSelf);
|
::DestroyWindow(_hSelf);
|
||||||
_hSelf = NULL;
|
_hSelf = NULL;
|
||||||
_pScintillaFunc = NULL;
|
_pScintillaFunc = NULL;
|
||||||
@ -862,8 +857,6 @@ public:
|
|||||||
bool pasteToMultiSelection() const;
|
bool pasteToMultiSelection() const;
|
||||||
void setElementColour(int element, COLORREF color) const { execute(SCI_SETELEMENTCOLOUR, element, color | 0xFF000000); };
|
void setElementColour(int element, COLORREF color) const { execute(SCI_SETELEMENTCOLOUR, element, color | 0xFF000000); };
|
||||||
|
|
||||||
Document getBlankDocument();
|
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
static bool _SciInit;
|
static bool _SciInit;
|
||||||
|
|
||||||
@ -885,10 +878,7 @@ protected:
|
|||||||
|
|
||||||
//Store the current buffer so it can be retrieved later
|
//Store the current buffer so it can be retrieved later
|
||||||
BufferID _currentBufferID = nullptr;
|
BufferID _currentBufferID = nullptr;
|
||||||
Buffer * _currentBuffer = nullptr;
|
Buffer* _currentBuffer = nullptr;
|
||||||
|
|
||||||
Buffer* _prevBuffer = nullptr;
|
|
||||||
Document _blankDocument = 0;
|
|
||||||
|
|
||||||
int _codepage = CP_ACP;
|
int _codepage = CP_ACP;
|
||||||
bool _wrapRestoreNeeded = false;
|
bool _wrapRestoreNeeded = false;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user