From e28324b8d09bd201911043bc74b6b8b10f5e1cb8 Mon Sep 17 00:00:00 2001 From: Don Ho Date: Fri, 10 Jan 2025 12:37:57 +0100 Subject: [PATCH] Fix reload losing syntax highlighting regression The regression is introduced by: https://github.com/notepad-plus-plus/notepad-plus-plus/commit/de9ffd2ea8507d033f7f111d8b48762f7d3b9436 Fix #16027, close #16042 --- PowerEditor/src/Notepad_plus.cpp | 2 ++ .../src/ScintillaComponent/ScintillaEditView.cpp | 12 +++++++----- .../src/ScintillaComponent/ScintillaEditView.h | 2 +- 3 files changed, 10 insertions(+), 6 deletions(-) diff --git a/PowerEditor/src/Notepad_plus.cpp b/PowerEditor/src/Notepad_plus.cpp index 350455e3d..58e58df1d 100644 --- a/PowerEditor/src/Notepad_plus.cpp +++ b/PowerEditor/src/Notepad_plus.cpp @@ -5034,6 +5034,7 @@ bool Notepad_plus::activateBuffer(BufferID id, int whichOne, bool forceApplyHili // Before switching off, synchronize backup file MainFileManager.backupCurrentBuffer(); } + Buffer * pBuf = MainFileManager.getBufferByID(id); bool reload = pBuf->getNeedReload(); if (reload) @@ -5041,6 +5042,7 @@ bool Notepad_plus::activateBuffer(BufferID id, int whichOne, bool forceApplyHili MainFileManager.reloadBuffer(id); pBuf->setNeedReload(false); } + if (whichOne == MAIN_VIEW) { if (_mainDocTab.activateBuffer(id)) //only activate if possible diff --git a/PowerEditor/src/ScintillaComponent/ScintillaEditView.cpp b/PowerEditor/src/ScintillaComponent/ScintillaEditView.cpp index 93a91a98a..1c8665cbd 100644 --- a/PowerEditor/src/ScintillaComponent/ScintillaEditView.cpp +++ b/PowerEditor/src/ScintillaComponent/ScintillaEditView.cpp @@ -2279,10 +2279,9 @@ bool ScintillaEditView::setLexerFromLangID(int langID) // Internal lexer only void ScintillaEditView::activateBuffer(BufferID buffer, bool force) { - if (buffer == BUFFER_INVALID) - return; - if (!force && buffer == _currentBuffer) - return; + if (buffer == BUFFER_INVALID) return; + if (!force && buffer == _currentBuffer) return; + Buffer * newBuf = MainFileManager.getBufferByID(buffer); // before activating another document, we get the current position @@ -2301,7 +2300,7 @@ void ScintillaEditView::activateBuffer(BufferID buffer, bool force) _currentBufferID = buffer; //the magical switch happens here _currentBuffer = newBuf; - const bool isSameLangType = _prevBuffer != nullptr && ((_prevBuffer == _currentBuffer) || (_prevBuffer->getLangType() == _currentBuffer->getLangType())); + const bool isSameLangType = (_prevBuffer != nullptr) && (_prevBuffer->getLangType() == _currentBuffer->getLangType()); const int currentLangInt = static_cast(_currentBuffer->getLangType()); const bool isFirstActiveBuffer = (_currentBuffer->getLastLangType() != currentLangInt); @@ -2324,6 +2323,9 @@ void ScintillaEditView::activateBuffer(BufferID buffer, bool force) execute(SCI_SETMODEVENTMASK, MODEVENTMASK_OFF); execute(SCI_SETDOCPOINTER, 0, _currentBuffer->getDocument()); execute(SCI_SETMODEVENTMASK, MODEVENTMASK_ON); + + if (force) + defineDocType(_currentBuffer->getLangType()); } else // Entering the tab for the 2nd or more times, with the different language type { diff --git a/PowerEditor/src/ScintillaComponent/ScintillaEditView.h b/PowerEditor/src/ScintillaComponent/ScintillaEditView.h index 72a10c2ac..4ce312bf5 100644 --- a/PowerEditor/src/ScintillaComponent/ScintillaEditView.h +++ b/PowerEditor/src/ScintillaComponent/ScintillaEditView.h @@ -453,7 +453,7 @@ public: } }; - void activateBuffer(BufferID buffer, bool force = false); + void activateBuffer(BufferID buffer, bool force); void getCurrentFoldStates(std::vector & lineStateVector); void syncFoldStateWith(const std::vector & lineStateVectorNew);