From 11accf92e93c574d60ef6a0c19a368d8957a68bb Mon Sep 17 00:00:00 2001 From: Don HO Date: Tue, 9 May 2017 01:59:05 +0200 Subject: [PATCH] Fix issue of lossing syntax highlighting during "save as" The new behaviour is: as user set a new syntax highlighting once, the new file extension of "save as" will be ignored. Fixes #1298 --- PowerEditor/src/NppCommands.cpp | 4 ++++ PowerEditor/src/ScitillaComponent/Buffer.cpp | 3 ++- PowerEditor/src/ScitillaComponent/Buffer.h | 4 ++++ 3 files changed, 10 insertions(+), 1 deletion(-) diff --git a/PowerEditor/src/NppCommands.cpp b/PowerEditor/src/NppCommands.cpp index d6f6d6a13..2a20a4d7c 100644 --- a/PowerEditor/src/NppCommands.cpp +++ b/PowerEditor/src/NppCommands.cpp @@ -2789,6 +2789,10 @@ void Notepad_plus::command(int id) case IDM_LANG_USER : { setLanguage(menuID2LangType(id)); + // Manually set language, don't change language even file extension changes. + Buffer *buffer = _pEditView->getCurrentBuffer(); + buffer->langHasBeenSetFromMenu(); + if (_pDocMap) { _pDocMap->setSyntaxHiliting(); diff --git a/PowerEditor/src/ScitillaComponent/Buffer.cpp b/PowerEditor/src/ScitillaComponent/Buffer.cpp index 2935527d4..7fee34d97 100644 --- a/PowerEditor/src/ScitillaComponent/Buffer.cpp +++ b/PowerEditor/src/ScitillaComponent/Buffer.cpp @@ -205,7 +205,8 @@ void Buffer::setFileName(const TCHAR *fn, LangType defaultLang) } updateTimeStamp(); - if (newLang != _lang || _lang == L_USER) + + if (!_hasLangBeenSetFromMenu && (newLang != _lang || _lang == L_USER)) { _lang = newLang; doNotify(BufferChangeFilename | BufferChangeLanguage | BufferChangeTimestamp); diff --git a/PowerEditor/src/ScitillaComponent/Buffer.h b/PowerEditor/src/ScitillaComponent/Buffer.h index 3568e03f8..daa81b93d 100644 --- a/PowerEditor/src/ScitillaComponent/Buffer.h +++ b/PowerEditor/src/ScitillaComponent/Buffer.h @@ -351,6 +351,8 @@ public: void setMapPosition(const MapPosition & mapPosition) { _mapPosition = mapPosition; }; MapPosition getMapPosition() const { return _mapPosition; }; + void langHasBeenSetFromMenu() { _hasLangBeenSetFromMenu = true; }; + private: int indexOfReference(const ScintillaEditView * identifier) const; @@ -408,5 +410,7 @@ private: HANDLE _eventHandle = nullptr; bool _isMonitoringOn = false; + bool _hasLangBeenSetFromMenu = false; + MapPosition _mapPosition; }; \ No newline at end of file