From 71be434a334d300487c5d23114dc4afd084b94aa Mon Sep 17 00:00:00 2001 From: Don Ho Date: Sun, 5 Jan 2025 05:13:20 +0100 Subject: [PATCH] Improve performance while disabling clickable URL link Ref: https://github.com/notepad-plus-plus/notepad-plus-plus/pull/15981#issuecomment-2570310216 Close #16021 --- PowerEditor/src/Notepad_plus.cpp | 2 ++ PowerEditor/src/NppBigSwitch.cpp | 47 ++++++++++++++++++++++------- PowerEditor/src/NppNotification.cpp | 23 +++++++++++--- 3 files changed, 57 insertions(+), 15 deletions(-) diff --git a/PowerEditor/src/Notepad_plus.cpp b/PowerEditor/src/Notepad_plus.cpp index 19f46d656..0497dc778 100644 --- a/PowerEditor/src/Notepad_plus.cpp +++ b/PowerEditor/src/Notepad_plus.cpp @@ -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); diff --git a/PowerEditor/src/NppBigSwitch.cpp b/PowerEditor/src/NppBigSwitch.cpp index b4548ac88..d924c46a0 100644 --- a/PowerEditor/src/NppBigSwitch.cpp +++ b/PowerEditor/src/NppBigSwitch.cpp @@ -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(); - addHotSpot(& _subEditView); + + int urlAction = nppParam.getNppGUI()._styleURL; + if (urlAction != urlDisable) + { + if (_mainEditView.getCurrentBuffer()->allowClickableLink()) + addHotSpot(&_mainEditView); + + if (_subEditView.getCurrentBuffer()->allowClickableLink()) + addHotSpot(&_subEditView); + } _findReplaceDlg.updateFinderScintilla(); @@ -3692,14 +3700,23 @@ LRESULT Notepad_plus::process(HWND hwnd, UINT message, WPARAM wParam, LPARAM lPa case NPPM_INTERNAL_UPDATECLICKABLELINKS: { ScintillaEditView* pView = reinterpret_cast(wParam); - if (pView == NULL) + + int urlAction = nppParam.getNppGUI()._styleURL; + if (urlAction != urlDisable) { - addHotSpot(_pEditView); - addHotSpot(_pNonEditView); - } - else - { - addHotSpot(pView); + 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(_pEditView->getCurrentBuffer())) - addHotSpot(_pEditView); + Buffer* currentBuf = _pEditView->getCurrentBuffer(); + if (wParam == reinterpret_cast(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(wParam); diff --git a/PowerEditor/src/NppNotification.cpp b/PowerEditor/src/NppNotification.cpp index f0c7a5542..b2f681679 100644 --- a/PowerEditor/src/NppNotification.cpp +++ b/PowerEditor/src/NppNotification.cpp @@ -188,7 +188,12 @@ BOOL Notepad_plus::notify(SCNotification *notification) if (!_isFolding) { - addHotSpot(); + int urlAction = (NppParameters::getInstance()).getNppGUI()._styleURL; + Buffer* currentBuf = _pEditView->getCurrentBuffer(); + if (urlAction != urlDisable && currentBuf->allowClickableLink()) + { + addHotSpot(); + } } if (_pDocMap) @@ -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) { - addHotSpot(notifyView); + 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) @@ -516,7 +526,12 @@ BOOL Notepad_plus::notify(SCNotification *notification) // if it's searching/replacing, then do nothing if ((_linkTriggered && !nppParam._isFindReplacing) || notification->wParam == LINKTRIGGERED) { - addHotSpot(); + int urlAction = (NppParameters::getInstance()).getNppGUI()._styleURL; + Buffer* currentBuf = _pEditView->getCurrentBuffer(); + if (urlAction != urlDisable && currentBuf->allowClickableLink()) + { + addHotSpot(); + } _linkTriggered = false; }