Improve performance while disabling clickable URL link

Ref: https://github.com/notepad-plus-plus/notepad-plus-plus/pull/15981#issuecomment-2570310216

Close #16021
This commit is contained in:
Don Ho 2025-01-05 05:13:20 +01:00
parent c5dd85cd93
commit 71be434a33
3 changed files with 57 additions and 15 deletions

View File

@ -3444,6 +3444,7 @@ void Notepad_plus::addHotSpot(ScintillaEditView* view)
{
if (_isAttemptingCloseOnQuit)
return; // don't recalculate URLs when shutting down
ScintillaEditView* pView = view ? view : _pEditView;
Buffer* currentBuf = pView->getCurrentBuffer();
@ -3466,6 +3467,7 @@ void Notepad_plus::addHotSpot(ScintillaEditView* view)
pView->getVisibleStartAndEndPosition(&startPos, &endPos);
if (startPos >= endPos) return;
pView->execute(SCI_SETINDICATORCURRENT, URL_INDIC);
if (urlAction == urlDisable || !currentBuf->allowClickableLink())
{
pView->execute(SCI_INDICATORCLEARRANGE, startPos, endPos - startPos);

View File

@ -2276,11 +2276,19 @@ LRESULT Notepad_plus::process(HWND hwnd, UINT message, WPARAM wParam, LPARAM lPa
//reset styler for change in Stylers.xml
_mainEditView.defineDocType(_mainEditView.getCurrentBuffer()->getLangType());
_mainEditView.performGlobalStyles();
addHotSpot(& _mainEditView);
_subEditView.defineDocType(_subEditView.getCurrentBuffer()->getLangType());
_subEditView.performGlobalStyles();
int urlAction = nppParam.getNppGUI()._styleURL;
if (urlAction != urlDisable)
{
if (_mainEditView.getCurrentBuffer()->allowClickableLink())
addHotSpot(&_mainEditView);
if (_subEditView.getCurrentBuffer()->allowClickableLink())
addHotSpot(&_subEditView);
}
_findReplaceDlg.updateFinderScintilla();
@ -3692,15 +3700,24 @@ LRESULT Notepad_plus::process(HWND hwnd, UINT message, WPARAM wParam, LPARAM lPa
case NPPM_INTERNAL_UPDATECLICKABLELINKS:
{
ScintillaEditView* pView = reinterpret_cast<ScintillaEditView*>(wParam);
int urlAction = nppParam.getNppGUI()._styleURL;
if (urlAction != urlDisable)
{
if (pView == NULL)
{
if (_pEditView->getCurrentBuffer()->allowClickableLink())
addHotSpot(_pEditView);
if (_pNonEditView->getCurrentBuffer()->allowClickableLink())
addHotSpot(_pNonEditView);
}
else
{
if (pView->getCurrentBuffer()->allowClickableLink())
addHotSpot(pView);
}
}
return TRUE;
}
@ -3734,8 +3751,16 @@ LRESULT Notepad_plus::process(HWND hwnd, UINT message, WPARAM wParam, LPARAM lPa
case NPPM_INTERNAL_DOCMODIFIEDBYREPLACEALL:
{
if (wParam == reinterpret_cast<WPARAM>(_pEditView->getCurrentBuffer()))
Buffer* currentBuf = _pEditView->getCurrentBuffer();
if (wParam == reinterpret_cast<WPARAM>(currentBuf))
{
int urlAction = nppParam.getNppGUI()._styleURL;
if (urlAction != urlDisable && currentBuf->allowClickableLink())
{
addHotSpot(_pEditView);
}
}
SCNotification scnN{};
scnN.nmhdr.code = NPPN_GLOBALMODIFIED;
scnN.nmhdr.hwndFrom = reinterpret_cast<void*>(wParam);

View File

@ -187,9 +187,14 @@ BOOL Notepad_plus::notify(SCNotification *notification)
size_t lineClicked = notification->line;
if (!_isFolding)
{
int urlAction = (NppParameters::getInstance()).getNppGUI()._styleURL;
Buffer* currentBuf = _pEditView->getCurrentBuffer();
if (urlAction != urlDisable && currentBuf->allowClickableLink())
{
addHotSpot();
}
}
if (_pDocMap)
_pDocMap->fold(lineClicked, _pEditView->isFolded(lineClicked));
@ -405,17 +410,22 @@ BOOL Notepad_plus::notify(SCNotification *notification)
NppParameters& nppParam = NppParameters::getInstance();
NppGUI& nppGui = nppParam.getNppGUI();
Buffer* currentBuf = notifyView->getCurrentBuffer();
// replacement for obsolete custom SCN_SCROLLED
if (notification->updated & SC_UPDATE_V_SCROLL)
{
int urlAction = (NppParameters::getInstance()).getNppGUI()._styleURL;
if (urlAction != urlDisable && currentBuf->allowClickableLink())
{
addHotSpot(notifyView);
}
}
// if it's searching/replacing, then do nothing
if (nppParam._isFindReplacing)
break;
Buffer* currentBuf = _pEditView->getCurrentBuffer();
if (notification->nmhdr.hwndFrom != _pEditView->getHSelf() && currentBuf->allowSmartHilite()) // notification come from unfocus view - both views ae visible
{
if (nppGui._smartHiliteOnAnotherView)
@ -515,8 +525,13 @@ BOOL Notepad_plus::notify(SCNotification *notification)
// if it's searching/replacing, then do nothing
if ((_linkTriggered && !nppParam._isFindReplacing) || notification->wParam == LINKTRIGGERED)
{
int urlAction = (NppParameters::getInstance()).getNppGUI()._styleURL;
Buffer* currentBuf = _pEditView->getCurrentBuffer();
if (urlAction != urlDisable && currentBuf->allowClickableLink())
{
addHotSpot();
}
_linkTriggered = false;
}