From b724a04eebc509ea70b5be0a0f5f4a4bac5a6bf8 Mon Sep 17 00:00:00 2001 From: Udo Hoffmann Date: Sat, 18 Jul 2020 13:18:01 +0200 Subject: [PATCH] Fix URL is opened inadvertently when clicking white space outside document Fix #8581, close #8584 --- PowerEditor/src/NppNotification.cpp | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/PowerEditor/src/NppNotification.cpp b/PowerEditor/src/NppNotification.cpp index 2652c71d..0de90538 100644 --- a/PowerEditor/src/NppNotification.cpp +++ b/PowerEditor/src/NppNotification.cpp @@ -817,18 +817,19 @@ BOOL Notepad_plus::notify(SCNotification *notification) // Check wether cursor is within URL auto indicMsk = notifyView->execute(SCI_INDICATORALLONFOR, notification->position); if (!(indicMsk & (1 << URL_INDIC))) break; - - // Revert selection of current word. Best to this early, otherwise the - // selected word is visible all the time while the browser is starting - notifyView->execute(SCI_SETSEL, notification->position, notification->position); + auto startPos = notifyView->execute(SCI_INDICATORSTART, URL_INDIC, notification->position); + auto endPos = notifyView->execute(SCI_INDICATOREND, URL_INDIC, notification->position); + if ((notification->position < startPos) || (notification->position > endPos)) break; // WM_LBUTTONUP goes to opening browser instead of Scintilla here, because the mouse is not captured. // The missing message causes mouse cursor flicker as soon as the mouse cursor is moved to a position outside the text editing area. ::PostMessage(notifyView->getHSelf(), WM_LBUTTONUP, 0, 0); + // Revert selection of current word. Best to this early, otherwise the + // selected word is visible all the time while the browser is starting + notifyView->execute(SCI_SETSEL, notification->position, notification->position); + // Open URL - auto startPos = notifyView->execute(SCI_INDICATORSTART, URL_INDIC, notification->position); - auto endPos = notifyView->execute(SCI_INDICATOREND, URL_INDIC, notification->position); generic_string url = notifyView->getGenericTextAsString(static_cast(startPos), static_cast(endPos)); ::ShellExecute(_pPublicInterface->getHSelf(), TEXT("open"), url.c_str(), NULL, NULL, SW_SHOW); }