From 6fd3830b42381f861f44967ddec6d5cebee2285f Mon Sep 17 00:00:00 2001 From: Don Ho Date: Wed, 29 Jan 2025 19:13:29 +0100 Subject: [PATCH] Add NPPM_ADDSCNMODIFIEDFLAGS to fix regression for Plugins Add **NPPM_ADDSCNMODIFIEDFLAGS** message for plugins which need the SCN_MODIFIED notification of other events. BOOL NPPM_ADDSCNMODIFIEDFLAGS(0, unsigned long scnMotifiedFlags2Add) Add needed SCN_MODIFIED flags so your plugin will recieve the notification SCN_MODIFIED of these events for your specific treatments. By default, Notepad++ only forwards SCN_MODIFIED with the following 5 flags/events SC_MOD_DELETETEXT | SC_MOD_INSERTTEXT | SC_PERFORMED_UNDO | SC_PERFORMED_REDO | SC_MOD_CHANGEINDICATOR to plugins. If your plugin need to process other events of SCN_MODIFIED, you should add the flags you need by sending this message to Notepad++, just after recieving NPPN_READY. wParam: 0 (not used) lParam[in]: scnMotifiedFlags2Add- Scintilla SCN_MODIFIED flags to add. Return TRUE Ref: https://community.notepad-plus-plus.org/topic/26588/notepad-v8-7-6-released/2?_=1738167940554 Fix #16121, close #16120 --- .../MISC/PluginsManager/Notepad_plus_msgs.h | 27 +++++++++++++++++++ PowerEditor/src/Notepad_plus.cpp | 1 + PowerEditor/src/NppBigSwitch.cpp | 6 +++++ PowerEditor/src/NppIO.cpp | 3 +++ PowerEditor/src/Parameters.h | 4 ++- PowerEditor/src/ScintillaComponent/Buffer.cpp | 1 + .../src/ScintillaComponent/GoToLineDlg.cpp | 1 + .../ScintillaComponent/ScintillaEditView.cpp | 10 ++++--- .../ScintillaComponent/ScintillaEditView.h | 3 +-- 9 files changed, 50 insertions(+), 6 deletions(-) diff --git a/PowerEditor/src/MISC/PluginsManager/Notepad_plus_msgs.h b/PowerEditor/src/MISC/PluginsManager/Notepad_plus_msgs.h index 4eb990ff8..c2264a550 100644 --- a/PowerEditor/src/MISC/PluginsManager/Notepad_plus_msgs.h +++ b/PowerEditor/src/MISC/PluginsManager/Notepad_plus_msgs.h @@ -990,6 +990,33 @@ enum Platform { PF_UNKNOWN, PF_X86, PF_X64, PF_IA64, PF_ARM64 }; // lParam[out]: language file name string receives all copied native language file name string // Return the number of char copied/to copy + #define NPPM_ADDSCNMODIFIEDFLAGS (NPPMSG + 117) + // BOOL NPPM_ADDSCNMODIFIEDFLAGS(0, unsigned long scnMotifiedFlags2Add) + // Add needed SCN_MODIFIED flags so your plugin will recieve the notification SCN_MODIFIED of these events for your specific treatments. + // By default, Notepad++ only forwards SCN_MODIFIED with the following 5 flags/events SC_MOD_DELETETEXT | SC_MOD_INSERTTEXT | SC_PERFORMED_UNDO | SC_PERFORMED_REDO | SC_MOD_CHANGEINDICATOR to plugins. + // If your plugin need to process other events of SCN_MODIFIED, you should add the flags you need by sending this message to Notepad++, just after recieving NPPN_READY. + // wParam: 0 (not used) + // lParam[in]: scnMotifiedFlags2Add - Scintilla SCN_MODIFIED flags to add. + // Return TRUE + // + // Example: + // + // extern "C" __declspec(dllexport) void beNotified(SCNotification* notifyCode) + // { + // switch (notifyCode->nmhdr.code) + // { + // case NPPN_READY: + // { + // // Add SC_MOD_DELETETEXT and SC_MOD_INSERTTEXT notifications + // ::SendMessage(nppData._nppHandle, NPPM_ADDSCNMODIFIEDFLAGS, 0, SC_MOD_DELETETEXT | SC_MOD_INSERTTEXT); + // } + // break; + // ... + // } + // ... + // } + + // For RUNCOMMAND_USER #define VAR_NOT_RECOGNIZED 0 #define FULL_CURRENT_PATH 1 diff --git a/PowerEditor/src/Notepad_plus.cpp b/PowerEditor/src/Notepad_plus.cpp index 38cd89afd..e1e4ada7a 100644 --- a/PowerEditor/src/Notepad_plus.cpp +++ b/PowerEditor/src/Notepad_plus.cpp @@ -3876,6 +3876,7 @@ void Notepad_plus::setLanguage(LangType langType) //If so, release one document bool reset = false; Document prev = 0; + unsigned long MODEVENTMASK_ON = NppParameters::getInstance().getScintillaModEventMask(); if (bothActive()) { if (_mainEditView.getCurrentBufferID() == _subEditView.getCurrentBufferID()) diff --git a/PowerEditor/src/NppBigSwitch.cpp b/PowerEditor/src/NppBigSwitch.cpp index ac7712f07..336b42981 100644 --- a/PowerEditor/src/NppBigSwitch.cpp +++ b/PowerEditor/src/NppBigSwitch.cpp @@ -3792,6 +3792,12 @@ LRESULT Notepad_plus::process(HWND hwnd, UINT message, WPARAM wParam, LPARAM lPa return fileName.length(); } + case NPPM_ADDSCNMODIFIEDFLAGS: + { + nppParam.addScintillaModEventMask(static_cast(lParam)); + return TRUE; + } + case NPPM_INTERNAL_HILITECURRENTLINE: { const ScintillaViewParams& svp = nppParam.getSVP(); diff --git a/PowerEditor/src/NppIO.cpp b/PowerEditor/src/NppIO.cpp index f13ce9e67..edd2ad44c 100644 --- a/PowerEditor/src/NppIO.cpp +++ b/PowerEditor/src/NppIO.cpp @@ -571,6 +571,7 @@ bool Notepad_plus::doReload(BufferID id, bool alert) //an empty Document is inserted during reload if needed. bool mainVisisble = (_mainEditView.getCurrentBufferID() == id); bool subVisisble = (_subEditView.getCurrentBufferID() == id); + unsigned long MODEVENTMASK_ON = NppParameters::getInstance().getScintillaModEventMask(); if (mainVisisble) { _mainEditView.saveCurrentPos(); @@ -2482,6 +2483,7 @@ bool Notepad_plus::loadSession(Session & session, bool isSnapshotMode, const wch //Force in the document so we can add the markers //Don't use default methods because of performance Document prevDoc = _mainEditView.execute(SCI_GETDOCPOINTER); + unsigned long MODEVENTMASK_ON = nppParam.getScintillaModEventMask(); _mainEditView.execute(SCI_SETMODEVENTMASK, MODEVENTMASK_OFF); _mainEditView.execute(SCI_SETDOCPOINTER, 0, buf->getDocument()); _mainEditView.execute(SCI_SETMODEVENTMASK, MODEVENTMASK_ON); @@ -2617,6 +2619,7 @@ bool Notepad_plus::loadSession(Session & session, bool isSnapshotMode, const wch //Force in the document so we can add the markers //Don't use default methods because of performance Document prevDoc = _subEditView.execute(SCI_GETDOCPOINTER); + unsigned long MODEVENTMASK_ON = nppParam.getScintillaModEventMask(); _subEditView.execute(SCI_SETMODEVENTMASK, MODEVENTMASK_OFF); _subEditView.execute(SCI_SETDOCPOINTER, 0, buf->getDocument()); _subEditView.execute(SCI_SETMODEVENTMASK, MODEVENTMASK_ON); diff --git a/PowerEditor/src/Parameters.h b/PowerEditor/src/Parameters.h index a63938ee6..6b6f2d41d 100644 --- a/PowerEditor/src/Parameters.h +++ b/PowerEditor/src/Parameters.h @@ -1852,6 +1852,8 @@ public: bool isStylerDocLoaded() const { return _pXmlUserStylerDoc != nullptr; }; ColumnEditorParam _columnEditParam; + unsigned long getScintillaModEventMask() const { return _sintillaModEventMask; }; + void addScintillaModEventMask(unsigned long mask2Add) { _sintillaModEventMask |= mask2Add; }; private: NppParameters(); @@ -2100,5 +2102,5 @@ private: int getCmdIdFromMenuEntryItemName(HMENU mainMenuHadle, const std::wstring& menuEntryName, const std::wstring& menuItemName); // return -1 if not found int getPluginCmdIdFromMenuEntryItemName(HMENU pluginsMenu, const std::wstring& pluginName, const std::wstring& pluginCmdName); // return -1 if not found winVer getWindowsVersion(); - + unsigned long _sintillaModEventMask = SC_MOD_DELETETEXT | SC_MOD_INSERTTEXT | SC_PERFORMED_UNDO | SC_PERFORMED_REDO | SC_MOD_CHANGEINDICATOR; }; diff --git a/PowerEditor/src/ScintillaComponent/Buffer.cpp b/PowerEditor/src/ScintillaComponent/Buffer.cpp index 4ee5aa420..3e20a5a67 100644 --- a/PowerEditor/src/ScintillaComponent/Buffer.cpp +++ b/PowerEditor/src/ScintillaComponent/Buffer.cpp @@ -1391,6 +1391,7 @@ SavingStatus FileManager::saveBuffer(BufferID id, const wchar_t* filename, bool if (isCopy) // "Save a Copy As..." command { + unsigned long MODEVENTMASK_ON = NppParameters::getInstance().getScintillaModEventMask(); _pscratchTilla->execute(SCI_SETMODEVENTMASK, MODEVENTMASK_OFF); _pscratchTilla->execute(SCI_SETDOCPOINTER, 0, _scratchDocDefault); _pscratchTilla->execute(SCI_SETMODEVENTMASK, MODEVENTMASK_ON); diff --git a/PowerEditor/src/ScintillaComponent/GoToLineDlg.cpp b/PowerEditor/src/ScintillaComponent/GoToLineDlg.cpp index 24ed1502e..fbdd59504 100644 --- a/PowerEditor/src/ScintillaComponent/GoToLineDlg.cpp +++ b/PowerEditor/src/ScintillaComponent/GoToLineDlg.cpp @@ -112,6 +112,7 @@ intptr_t CALLBACK GoToLineDlg::run_dlgProc(UINT message, WPARAM wParam, LPARAM l (*_ppEditView)->execute(SCI_GOTOPOS, posToGoto); } } + unsigned long MODEVENTMASK_ON = NppParameters::getInstance().getScintillaModEventMask(); (*_ppEditView)->execute(SCI_SETMODEVENTMASK, MODEVENTMASK_ON); SCNotification notification{}; diff --git a/PowerEditor/src/ScintillaComponent/ScintillaEditView.cpp b/PowerEditor/src/ScintillaComponent/ScintillaEditView.cpp index fb6c1d4e6..021532f53 100644 --- a/PowerEditor/src/ScintillaComponent/ScintillaEditView.cpp +++ b/PowerEditor/src/ScintillaComponent/ScintillaEditView.cpp @@ -252,8 +252,9 @@ void ScintillaEditView::init(HINSTANCE hInst, HWND hPere) const COLORREF hiddenLinesGreen = RGB(0x77, 0xCC, 0x77); long hiddenLinesGreenWithAlpha = hiddenLinesGreen | 0xFF000000; setElementColour(SC_ELEMENT_HIDDEN_LINE, hiddenLinesGreenWithAlpha); - - if (NppParameters::getInstance()._dpiManager.scaleX(100) >= 150) + + NppParameters& nppParams = NppParameters::getInstance(); + if (nppParams._dpiManager.scaleX(100) >= 150) { execute(SCI_RGBAIMAGESETWIDTH, 18); execute(SCI_RGBAIMAGESETHEIGHT, 18); @@ -311,7 +312,7 @@ void ScintillaEditView::init(HINSTANCE hInst, HWND hPere) execute(SCI_INDICSETUNDER, SCE_UNIVERSAL_FOUND_STYLE_EXT4, true); execute(SCI_INDICSETUNDER, SCE_UNIVERSAL_FOUND_STYLE_EXT5, true); - NppGUI& nppGui = (NppParameters::getInstance()).getNppGUI(); + NppGUI& nppGui = nppParams.getNppGUI(); HMODULE hNtdllModule = ::GetModuleHandle(L"ntdll.dll"); FARPROC isWINE = nullptr; @@ -347,6 +348,7 @@ void ScintillaEditView::init(HINSTANCE hInst, HWND hPere) delete[] defaultCharList; } } + unsigned long MODEVENTMASK_ON = nppParams.getScintillaModEventMask(); execute(SCI_SETMODEVENTMASK, MODEVENTMASK_ON); //Get the startup document and make a buffer for it so it can be accessed like a file attachDefaultDoc(); @@ -382,6 +384,7 @@ LRESULT CALLBACK ScintillaEditView::scintillaStatic_Proc(HWND hwnd, UINT Message return ::DefWindowProc(hwnd, Message, wParam, lParam); } + LRESULT ScintillaEditView::scintillaNew_Proc(HWND hwnd, UINT Message, WPARAM wParam, LPARAM lParam) { switch (Message) @@ -2301,6 +2304,7 @@ void ScintillaEditView::activateBuffer(BufferID buffer, bool force) const int currentLangInt = static_cast(_currentBuffer->getLangType()); const bool isFirstActiveBuffer = (_currentBuffer->getLastLangType() != currentLangInt); + unsigned long MODEVENTMASK_ON = NppParameters::getInstance().getScintillaModEventMask(); if (isFirstActiveBuffer) // Entering the tab for the 1st time { // change the doc, this operation will decrease diff --git a/PowerEditor/src/ScintillaComponent/ScintillaEditView.h b/PowerEditor/src/ScintillaComponent/ScintillaEditView.h index 4ce312bf5..0b61c14da 100644 --- a/PowerEditor/src/ScintillaComponent/ScintillaEditView.h +++ b/PowerEditor/src/ScintillaComponent/ScintillaEditView.h @@ -93,8 +93,7 @@ const bool fold_uncollapse = true; const bool fold_collapse = false; #define MAX_FOLD_COLLAPSE_LEVEL 8 -#define MODEVENTMASK_OFF 0 -#define MODEVENTMASK_ON SC_MOD_DELETETEXT | SC_MOD_INSERTTEXT | SC_PERFORMED_UNDO | SC_PERFORMED_REDO | SC_MOD_CHANGEINDICATOR +#define MODEVENTMASK_OFF 0 enum TextCase : UCHAR {