From 49e6957d486c360e05ba85ceb1c179a891831779 Mon Sep 17 00:00:00 2001 From: Don Ho Date: Wed, 21 Feb 2024 04:08:41 +0100 Subject: [PATCH] Fix Replace All action not notifying plugins of modification regression Add NPPN_GLOBALMODIFIED to notify plugins that the current document is just modified by Replace All action. //scnNotification->nmhdr.code = NPPN_GLOBALMODIFIED; //scnNotification->nmhdr.hwndFrom = BufferID; //scnNotification->nmhdr.idFrom = 0; // preserved for the future use, must be zero For solving the performance issue (from v8.6.4), Notepad++ doesn't trigger SCN_MODIFIED & other Scitilla notifications during Replace All action anymore. Plugin devs should monitor NPPN_GLOBALMODIFIED instead. This notification is implemented in Notepad++ v8.6.5. Ref: https://github.com/notepad-plus-plus/notepad-plus-plus/pull/14685#issuecomment-1955229867 Fix #14767, close #14768 --- .../src/MISC/PluginsManager/Notepad_plus_msgs.h | 15 +++++++++++---- PowerEditor/src/NppBigSwitch.cpp | 10 ++++++++++ .../src/ScintillaComponent/FindReplaceDlg.cpp | 5 ++++- PowerEditor/src/WinControls/Grid/BabyGrid.cpp | 2 +- .../src/WinControls/Grid/ShortcutMapper.cpp | 2 +- PowerEditor/src/resource.h | 1 + 6 files changed, 28 insertions(+), 7 deletions(-) diff --git a/PowerEditor/src/MISC/PluginsManager/Notepad_plus_msgs.h b/PowerEditor/src/MISC/PluginsManager/Notepad_plus_msgs.h index cad16dce5..90a517958 100644 --- a/PowerEditor/src/MISC/PluginsManager/Notepad_plus_msgs.h +++ b/PowerEditor/src/MISC/PluginsManager/Notepad_plus_msgs.h @@ -1047,7 +1047,7 @@ enum Platform { PF_UNKNOWN, PF_X86, PF_X64, PF_IA64, PF_ARM64 }; //scnNotification->nmhdr.idFrom = BufferID; #define NPPN_FILEBEFORESAVE (NPPN_FIRST + 7) // To notify plugins that the current file is about to be saved - //scnNotification->nmhdr.code = NPPN_FILEBEFOREOPEN; + //scnNotification->nmhdr.code = NPPN_FILEBEFORESAVE; //scnNotification->nmhdr.hwndFrom = hwndNpp; //scnNotification->nmhdr.idFrom = BufferID; @@ -1077,7 +1077,7 @@ enum Platform { PF_UNKNOWN, PF_X86, PF_X64, PF_IA64, PF_ARM64 }; //scnNotification->nmhdr.idFrom = currentBufferID; #define NPPN_SHORTCUTREMAPPED (NPPN_FIRST + 13) // To notify plugins that plugin command shortcut is remapped. - //scnNotification->nmhdr.code = NPPN_SHORTCUTSREMAPPED; + //scnNotification->nmhdr.code = NPPN_SHORTCUTREMAPPED; //scnNotification->nmhdr.hwndFrom = ShortcutKeyStructurePointer; //scnNotification->nmhdr.idFrom = cmdID; //where ShortcutKeyStructurePointer is pointer of struct ShortcutKey: @@ -1089,12 +1089,12 @@ enum Platform { PF_UNKNOWN, PF_X86, PF_X64, PF_IA64, PF_ARM64 }; //}; #define NPPN_FILEBEFORELOAD (NPPN_FIRST + 14) // To notify plugins that the current file is about to be loaded - //scnNotification->nmhdr.code = NPPN_FILEBEFOREOPEN; + //scnNotification->nmhdr.code = NPPN_FILEBEFORELOAD; //scnNotification->nmhdr.hwndFrom = hwndNpp; //scnNotification->nmhdr.idFrom = NULL; #define NPPN_FILELOADFAILED (NPPN_FIRST + 15) // To notify plugins that file open operation failed - //scnNotification->nmhdr.code = NPPN_FILEOPENFAILED; + //scnNotification->nmhdr.code = NPPN_FILELOADFAILED; //scnNotification->nmhdr.hwndFrom = hwndNpp; //scnNotification->nmhdr.idFrom = BufferID; @@ -1172,3 +1172,10 @@ enum Platform { PF_UNKNOWN, PF_X86, PF_X64, PF_IA64, PF_ARM64 }; //scnNotification->nmhdr.code = NPPN_EXTERNALLEXERBUFFER; //scnNotification->nmhdr.hwndFrom = hwndNpp; //scnNotification->nmhdr.idFrom = BufferID; //where pluginMessage is pointer of type wchar_t + + #define NPPN_GLOBALMODIFIED (NPPN_FIRST + 30) // To notify plugins that the current document is just modified by Replace All action. For solving the performance issue (from v8.6.4), + // Notepad++ doesn't trigger SCN_MODIFIED & other Scitilla notifications during Replace All action anymore. + // Plugin devs should monitor NPPN_GLOBALMODIFIED instead. This notification is implemented in Notepad++ v8.6.5. + //scnNotification->nmhdr.code = NPPN_GLOBALMODIFIED; + //scnNotification->nmhdr.hwndFrom = BufferID; + //scnNotification->nmhdr.idFrom = 0; // preserved for the future use, must be zero diff --git a/PowerEditor/src/NppBigSwitch.cpp b/PowerEditor/src/NppBigSwitch.cpp index 70bfda5e7..69e61699a 100644 --- a/PowerEditor/src/NppBigSwitch.cpp +++ b/PowerEditor/src/NppBigSwitch.cpp @@ -3516,6 +3516,16 @@ LRESULT Notepad_plus::process(HWND hwnd, UINT message, WPARAM wParam, LPARAM lPa return TRUE; } + case NPPM_INTERNAL_DOCMODIFIEDBYREPLACEALL: + { + SCNotification scnN{}; + scnN.nmhdr.code = NPPN_GLOBALMODIFIED; + scnN.nmhdr.hwndFrom = reinterpret_cast(_pEditView->getCurrentBuffer()); + scnN.nmhdr.idFrom = 0; + _pluginsManager.notify(&scnN); + return TRUE; + } + default: { if (message == WDN_NOTIFY) diff --git a/PowerEditor/src/ScintillaComponent/FindReplaceDlg.cpp b/PowerEditor/src/ScintillaComponent/FindReplaceDlg.cpp index 5a997eddb..b7a436e3a 100644 --- a/PowerEditor/src/ScintillaComponent/FindReplaceDlg.cpp +++ b/PowerEditor/src/ScintillaComponent/FindReplaceDlg.cpp @@ -2816,7 +2816,10 @@ int FindReplaceDlg::processAll(ProcessOperation op, const FindOption *opt, bool // Turn ON the notifications after operations (*_ppEditView)->execute(SCI_SETMODEVENTMASK, notifFlag); if (op == ProcessReplaceAll && nbProcessed > 0) // All the notification of modification (SCN_MODIFIED) were removed during the operations, so we set modified status true here + { (*_ppEditView)->getCurrentBuffer()->setModifiedStatus(true); + ::SendMessage(_hParent, NPPM_INTERNAL_DOCMODIFIEDBYREPLACEALL, 0, 0); + } if (nbProcessed == FIND_INVALID_REGULAR_EXPRESSION) @@ -4750,7 +4753,7 @@ void Finder::addSearchResultInfo(int count, int countSearched, bool searchedEnti generic_string hitsIn = count == 1 ? TEXT("hit") : TEXT("hits"); - generic_string fileOrSelection = searchedEntireNotSelection ? TEXT("file") : TEXT("selection");; + generic_string fileOrSelection = searchedEntireNotSelection ? TEXT("file") : TEXT("selection"); if (_nbFoundFiles != 1) { fileOrSelection += TEXT("s"); diff --git a/PowerEditor/src/WinControls/Grid/BabyGrid.cpp b/PowerEditor/src/WinControls/Grid/BabyGrid.cpp index fa14c0578..e832d3683 100644 --- a/PowerEditor/src/WinControls/Grid/BabyGrid.cpp +++ b/PowerEditor/src/WinControls/Grid/BabyGrid.cpp @@ -1311,7 +1311,7 @@ int FindLongestLine(HDC hdc, wchar_t* text, SIZE* size) { int longest = 0; wchar_t* buffer = nullptr; - wchar_t* token = WCSTOK(text, TEXT("\n"), &buffer);; + wchar_t* token = WCSTOK(text, TEXT("\n"), &buffer); while (token) { diff --git a/PowerEditor/src/WinControls/Grid/ShortcutMapper.cpp b/PowerEditor/src/WinControls/Grid/ShortcutMapper.cpp index da7f0a95d..d7fa6640d 100644 --- a/PowerEditor/src/WinControls/Grid/ShortcutMapper.cpp +++ b/PowerEditor/src/WinControls/Grid/ShortcutMapper.cpp @@ -1385,7 +1385,7 @@ bool ShortcutMapper::findKeyConflicts(__inout_opt generic_string * const keyConf *keyConflictLocation += TEXT(" | "); *keyConflictLocation += std::to_wstring(itemIndex + 1); *keyConflictLocation += TEXT(" "); - *keyConflictLocation += string2wstring(vShortcuts[itemIndex].getName(), CP_UTF8);; + *keyConflictLocation += string2wstring(vShortcuts[itemIndex].getName(), CP_UTF8); *keyConflictLocation += TEXT(" ( "); *keyConflictLocation += string2wstring(vShortcuts[itemIndex].toString(), CP_UTF8); *keyConflictLocation += TEXT(" )"); diff --git a/PowerEditor/src/resource.h b/PowerEditor/src/resource.h index fb80d2e9f..e8319e5f1 100644 --- a/PowerEditor/src/resource.h +++ b/PowerEditor/src/resource.h @@ -657,6 +657,7 @@ #define NPPM_INTERNAL_EXTERNALLEXERBUFFER (NOTEPADPLUS_USER_INTERNAL + 76) #define NPPM_INTERNAL_CHECKUNDOREDOSTATE (NOTEPADPLUS_USER_INTERNAL + 77) #define NPPM_INTERNAL_LINECUTCOPYWITHOUTSELECTION (NOTEPADPLUS_USER_INTERNAL + 78) + #define NPPM_INTERNAL_DOCMODIFIEDBYREPLACEALL (NOTEPADPLUS_USER_INTERNAL + 79) // See Notepad_plus_msgs.h //#define NOTEPADPLUS_USER (WM_USER + 1000)