Fix Replace All crash & performance issue

Fix  #14630, close #14685
pull/14697/head
Don Ho 2024-02-06 19:34:22 +01:00
parent 0d05dae4ba
commit 044296eea1
2 changed files with 19 additions and 1 deletions

View File

@ -2737,12 +2737,19 @@ int FindReplaceDlg::processAll(ProcessOperation op, const FindOption *opt, bool
{
if (op == ProcessReplaceAll && (*_ppEditView)->getCurrentBuffer()->isReadOnly())
{
NativeLangSpeaker *pNativeSpeaker = (NppParameters::getInstance()).getNativeLangSpeaker();
NppParameters& nppParam = NppParameters::getInstance();
NativeLangSpeaker *pNativeSpeaker = nppParam.getNativeLangSpeaker();
generic_string msg = pNativeSpeaker->getLocalizedStrFromID("find-status-replaceall-readonly", TEXT("Replace All: Cannot replace text. The current document is read only."));
setStatusbarMessage(msg, FSNotFound);
return 0;
}
// Turn OFF all the notification of modification (SCN_MODIFIED) for the sake of performance
LRESULT notifFlag = (*_ppEditView)->execute(SCI_GETMODEVENTMASK);
(*_ppEditView)->execute(SCI_SETMODEVENTMASK, 0);
const FindOption *pOptions = opt?opt:_env;
const TCHAR *txt2find = pOptions->_str2Search.c_str();
const TCHAR *txt2replace = pOptions->_str4Replace.c_str();
@ -2805,6 +2812,13 @@ int FindReplaceDlg::processAll(ProcessOperation op, const FindOption *opt, bool
int nbProcessed = processRange(op, findReplaceInfo, pFindersInfo, pOptions, colourStyleID);
// 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);
if (nbProcessed == FIND_INVALID_REGULAR_EXPRESSION)
return FIND_INVALID_REGULAR_EXPRESSION;

View File

@ -234,6 +234,10 @@ void ScintillaEditView::init(HINSTANCE hInst, HWND hPere)
throw std::runtime_error("ScintillaEditView::init : SCI_GETDIRECTPOINTER message failed");
}
// Set only the notification we need.
execute(SCI_SETMODEVENTMASK, SC_MOD_DELETETEXT | SC_MOD_INSERTTEXT | SC_PERFORMED_UNDO | SC_PERFORMED_REDO | SC_MOD_CHANGEINDICATOR);
execute(SCI_SETCOMMANDEVENTS, false);
execute(SCI_SETMARGINMASKN, _SC_MARGE_FOLDER, SC_MASK_FOLDERS);
showMargin(_SC_MARGE_FOLDER, true);