Skip to content

Commit 044296e

Browse files
committed
Fix Replace All crash & performance issue
Fix #14630, close #14685
1 parent 0d05dae commit 044296e

File tree

2 files changed

+19
-1
lines changed

2 files changed

+19
-1
lines changed

PowerEditor/src/ScintillaComponent/FindReplaceDlg.cpp

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2737,12 +2737,19 @@ int FindReplaceDlg::processAll(ProcessOperation op, const FindOption *opt, bool
27372737
{
27382738
if (op == ProcessReplaceAll && (*_ppEditView)->getCurrentBuffer()->isReadOnly())
27392739
{
2740-
NativeLangSpeaker *pNativeSpeaker = (NppParameters::getInstance()).getNativeLangSpeaker();
2740+
NppParameters& nppParam = NppParameters::getInstance();
2741+
NativeLangSpeaker *pNativeSpeaker = nppParam.getNativeLangSpeaker();
27412742
generic_string msg = pNativeSpeaker->getLocalizedStrFromID("find-status-replaceall-readonly", TEXT("Replace All: Cannot replace text. The current document is read only."));
27422743
setStatusbarMessage(msg, FSNotFound);
27432744
return 0;
27442745
}
27452746

2747+
// Turn OFF all the notification of modification (SCN_MODIFIED) for the sake of performance
2748+
LRESULT notifFlag = (*_ppEditView)->execute(SCI_GETMODEVENTMASK);
2749+
(*_ppEditView)->execute(SCI_SETMODEVENTMASK, 0);
2750+
2751+
2752+
27462753
const FindOption *pOptions = opt?opt:_env;
27472754
const TCHAR *txt2find = pOptions->_str2Search.c_str();
27482755
const TCHAR *txt2replace = pOptions->_str4Replace.c_str();
@@ -2805,6 +2812,13 @@ int FindReplaceDlg::processAll(ProcessOperation op, const FindOption *opt, bool
28052812

28062813
int nbProcessed = processRange(op, findReplaceInfo, pFindersInfo, pOptions, colourStyleID);
28072814

2815+
2816+
// Turn ON the notifications after operations
2817+
(*_ppEditView)->execute(SCI_SETMODEVENTMASK, notifFlag);
2818+
if (op == ProcessReplaceAll && nbProcessed > 0) // All the notification of modification (SCN_MODIFIED) were removed during the operations, so we set modified status true here
2819+
(*_ppEditView)->getCurrentBuffer()->setModifiedStatus(true);
2820+
2821+
28082822
if (nbProcessed == FIND_INVALID_REGULAR_EXPRESSION)
28092823
return FIND_INVALID_REGULAR_EXPRESSION;
28102824

PowerEditor/src/ScintillaComponent/ScintillaEditView.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -234,6 +234,10 @@ void ScintillaEditView::init(HINSTANCE hInst, HWND hPere)
234234
throw std::runtime_error("ScintillaEditView::init : SCI_GETDIRECTPOINTER message failed");
235235
}
236236

237+
// Set only the notification we need.
238+
execute(SCI_SETMODEVENTMASK, SC_MOD_DELETETEXT | SC_MOD_INSERTTEXT | SC_PERFORMED_UNDO | SC_PERFORMED_REDO | SC_MOD_CHANGEINDICATOR);
239+
execute(SCI_SETCOMMANDEVENTS, false);
240+
237241
execute(SCI_SETMARGINMASKN, _SC_MARGE_FOLDER, SC_MASK_FOLDERS);
238242
showMargin(_SC_MARGE_FOLDER, true);
239243

0 commit comments

Comments
 (0)