Fix URL is opened inadvertently when clicking white space outside document

Fix #8581, close #8584
This commit is contained in:
Udo Hoffmann 2020-07-18 13:18:01 +02:00 committed by Don HO
parent efd7b56af9
commit b724a04eeb
No known key found for this signature in database
GPG Key ID: 6C429F1D8D84F46E

View File

@ -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<size_t>(startPos), static_cast<size_t>(endPos));
::ShellExecute(_pPublicInterface->getHSelf(), TEXT("open"), url.c_str(), NULL, NULL, SW_SHOW);
}