diff --git a/src/Edit.c b/src/Edit.c index 9bb16ddd3..a3d392183 100644 --- a/src/Edit.c +++ b/src/Edit.c @@ -5795,26 +5795,29 @@ void EditCompleteWord(HWND hwnd, BOOL autoInsert) { // void EditUpdateUrlHotspots(HWND hwnd, int startPos, int endPos, BOOL bActiveHotspot) { - const char* pszUrlRegEx = "\\b(?:(?:https?|ftp|file)://|www\\.|ftp\\.)" - "(?:\\([-A-Z0-9+&@#/%=~_|$?!:,.]*\\)|[-A-Z0-9+&@#/%=~_|$?!:,.])*" - "(?:\\([-A-Z0-9+&@#/%=~_|$?!:,.]*\\)|[A-Z0-9+&@#/%=~_|$])"; - - const int iRegExLen = (int)strlen(pszUrlRegEx); - if (endPos < startPos) { int tmp = startPos; startPos = endPos; endPos = tmp; // swap } + + const char* pszUrlRegEx = "\\b(?:(?:https?|ftp|file)://|www\\.|ftp\\.)" + "(?:\\([-A-Z0-9+&@#/%=~_|$?!:,.]*\\)|[-A-Z0-9+&@#/%=~_|$?!:,.])*" + "(?:\\([-A-Z0-9+&@#/%=~_|$?!:,.]*\\)|[A-Z0-9+&@#/%=~_|$])"; + + const int iRegExLen = (int)strlen(pszUrlRegEx); + if (startPos < 0) { // current line only int currPos = SciCall_GetCurrentPos(); int lineNo = SciCall_LineFromPosition(currPos); startPos = SciCall_PositionFromLine(lineNo); endPos = SciCall_GetLineEndPosition(lineNo); } - if (endPos == startPos) + if (endPos == startPos) return; int start = startPos; int end = endPos; + int iStyle = bActiveHotspot ? Style_GetHotspotStyleID() : STYLE_DEFAULT; + do { int iPos = EditFindInTarget(hwnd, pszUrlRegEx, iRegExLen, SCFIND_NP3_REGEX, &start, &end, FALSE); @@ -5823,20 +5826,23 @@ void EditUpdateUrlHotspots(HWND hwnd, int startPos, int endPos, BOOL bActiveHots // mark this match SciCall_StartStyling(iPos); - SciCall_SetStyling((end - start), Style_GetHotspotID()); + SciCall_SetStyling((end - start), iStyle); // next occurrence start = end; end = endPos; - } - while (start < end); - SciCall_StartStyling(endPos); + } while (start < end); - if (bActiveHotspot) + if (bActiveHotspot) + { + SciCall_StartStyling(endPos); UpdateEditWndUI(); - else + } + else { + SciCall_StartStyling(startPos); SendMessage(hwnd, SCI_COLOURISE, 0, (LPARAM)-1); + } } diff --git a/src/Notepad3.c b/src/Notepad3.c index 4edb8ffa4..6ac5a598b 100644 --- a/src/Notepad3.c +++ b/src/Notepad3.c @@ -2442,8 +2442,11 @@ void MsgInitMenu(HWND hwnd,WPARAM wParam,LPARAM lParam) i = (StringCchLenW(szIniFile,COUNTOF(szIniFile)) > 0 || StringCchLenW(szIniFile2,COUNTOF(szIniFile2)) > 0); EnableCmd(hmenu,IDM_VIEW_SAVESETTINGSNOW,bEnableSaveSettings && i); - BOOL bIsHLink = ((int)SendMessage(hwndEdit, SCI_GETSTYLEAT, - SendMessage(hwndEdit, SCI_GETCURRENTPOS, 0, 0), 0) == Style_GetHotspotID(hwndEdit)); + BOOL bIsHLink = FALSE; + if ((BOOL)SendMessage(hwndEdit, SCI_STYLEGETHOTSPOT, Style_GetHotspotStyleID(), 0)) + { + bIsHLink = (int)SendMessage(hwndEdit, SCI_GETSTYLEAT, SendMessage(hwndEdit, SCI_GETCURRENTPOS, 0, 0), 0) == Style_GetHotspotStyleID(); + } EnableCmd(hmenu, CMD_OPEN_HYPERLINK, bIsHLink); UNUSED(lParam); @@ -5361,9 +5364,12 @@ void OpenHotSpotURL(int position, BOOL bForceBrowser) { int iStyle = (int)SendMessage(hwndEdit, SCI_GETSTYLEAT, position, 0); - if (Style_GetHotspotID(hwndEdit) != iStyle) + if (Style_GetHotspotStyleID() != iStyle) return; + if (!(BOOL)SendMessage(hwndEdit, SCI_STYLEGETHOTSPOT, Style_GetHotspotStyleID(), 0)) + return; + // get left most position of style int pos = position; int iNewStyle = iStyle; @@ -5479,12 +5485,12 @@ LRESULT MsgNotify(HWND hwnd,WPARAM wParam,LPARAM lParam) } break; - case SCN_STYLENEEDED: // this event needs SCI_SETLEXER(SCLEX_CONTAINER) - { - int lineNumber = SciCall_LineFromPosition(SciCall_GetEndStyled()); - EditUpdateUrlHotspots(hwndEdit, SciCall_PositionFromLine(lineNumber), (int)scn->position, bHyperlinkHotspot); - } - break; + //case SCN_STYLENEEDED: // this event needs SCI_SETLEXER(SCLEX_CONTAINER) + // { + // int lineNumber = SciCall_LineFromPosition(SciCall_GetEndStyled()); + // EditUpdateUrlHotspots(hwndEdit, SciCall_PositionFromLine(lineNumber), (int)scn->position, bHyperlinkHotspot); + // } + // break; case SCN_UPDATEUI: if (scn->updated & ~(SC_UPDATE_V_SCROLL | SC_UPDATE_H_SCROLL)) diff --git a/src/Styles.c b/src/Styles.c index 1aeda40b2..8c6276949 100644 --- a/src/Styles.c +++ b/src/Styles.c @@ -3172,8 +3172,6 @@ void Style_SetLexer(HWND hwnd, PEDITLEXER pLexNew) { // -------------------------------------------------------------------------- - Style_SetUrlHotSpot(hwnd, TRUE); - Style_SetStyles(hwnd, lexDefault.Styles[STY_MARGIN + iIdx].iStyle, lexDefault.Styles[STY_MARGIN + iIdx].szValue); // linenumber if (bUseOldStyleBraceMatching) { @@ -3435,6 +3433,7 @@ void Style_SetLexer(HWND hwnd, PEDITLEXER pLexNew) { if (SendMessage(hwnd,SCI_GETINDENTATIONGUIDES,0,0) != SC_IV_NONE) Style_SetIndentGuides(hwnd,TRUE); + if (pLexNew->iLexer != SCLEX_NULL || pLexNew == &lexANSI) { int j; @@ -3534,9 +3533,11 @@ void Style_SetLexer(HWND hwnd, PEDITLEXER pLexNew) { } // apply lexer styles + Style_SetUrlHotSpot(hwnd, TRUE); SendMessage(hwnd, SCI_COLOURISE, 0, (LPARAM)-1); - // override lexer style by hyperlink hotspot style + // update UI for hotspots + Style_SetUrlHotSpot(hwnd, bHyperlinkHotspot); EditUpdateUrlHotspots(hwnd, 0, SciCall_GetTextLength(), bHyperlinkHotspot); // Save current lexer @@ -3547,14 +3548,11 @@ void Style_SetLexer(HWND hwnd, PEDITLEXER pLexNew) { //============================================================================= // -// Style_GetHotspotID() +// Style_GetHotspotStyleID() // -int Style_GetHotspotID() +int Style_GetHotspotStyleID() { - if (bHyperlinkHotspot) { - return (bUse2ndDefaultStyle ? (STYLE_LASTPREDEFINED + STY_URL_HOTSPOT + STY_CNT_LAST) : (STYLE_LASTPREDEFINED + STY_URL_HOTSPOT)); - } - return (bUse2ndDefaultStyle ? (STY_DEFAULT + STY_CNT_LAST) : STY_DEFAULT); + return (bUse2ndDefaultStyle ? (STYLE_LASTPREDEFINED + STY_URL_HOTSPOT + STY_CNT_LAST) : (STYLE_LASTPREDEFINED + STY_URL_HOTSPOT)); } @@ -3568,7 +3566,7 @@ void Style_SetUrlHotSpot(HWND hwnd, BOOL bHotSpot) int iIdx = (bUse2ndDefaultStyle) ? STY_CNT_LAST : 0; // Hot Spot settings - const int iStyleHotSpot = Style_GetHotspotID(); + const int iStyleHotSpot = Style_GetHotspotStyleID(); if (bHotSpot) { diff --git a/src/Styles.h b/src/Styles.h index 9982fa25f..c4f895e69 100644 --- a/src/Styles.h +++ b/src/Styles.h @@ -102,7 +102,7 @@ INT_PTR CALLBACK Styles_ConfigDlgProc(HWND,UINT,WPARAM,LPARAM); void Style_ConfigDlg(HWND); INT_PTR CALLBACK Style_SelectLexerDlgProc(HWND,UINT,WPARAM,LPARAM); void Style_SelectLexerDlg(HWND); -int Style_GetHotspotID(); +int Style_GetHotspotStyleID(); #endif //_NP3_STYLES_H_