From 1a9df16b008c77fc8200a7ed746b348e320627b4 Mon Sep 17 00:00:00 2001 From: George Hazan Date: Fri, 18 Aug 2023 19:11:47 +0300 Subject: NewStory: correct URL length calculation --- plugins/NewStory/src/history_array.cpp | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) (limited to 'plugins/NewStory') diff --git a/plugins/NewStory/src/history_array.cpp b/plugins/NewStory/src/history_array.cpp index 8dcfb98d7b..9f53abd1df 100644 --- a/plugins/NewStory/src/history_array.cpp +++ b/plugins/NewStory/src/history_array.cpp @@ -117,12 +117,11 @@ bool ItemData::isLink(POINT pt, CMStringW *pwszUrl) const if (pwszUrl) { CHARRANGE sel = { cp, cp }; - for (sel.cpMin = cp; sel.cpMin >= 0; sel.cpMin--) - if (!isLinkChar(sel.cpMin)) - break; - - for (sel.cpMax = cp + 1; isLinkChar(sel.cpMax); sel.cpMax++) - ; + while (isLinkChar(sel.cpMin-1)) + sel.cpMin--; + + while (isLinkChar(sel.cpMax)) + sel.cpMax++; if (sel.cpMax > sel.cpMin) { pwszUrl->Truncate(sel.cpMax - sel.cpMin + 1); @@ -142,6 +141,9 @@ bool ItemData::isLink(POINT pt, CMStringW *pwszUrl) const bool ItemData::isLinkChar(int idx) const { + if (idx < 0) + return false; + CHARRANGE sel = { idx, idx + 1 }; MTextSendMessage(0, data, EM_EXSETSEL, 0, LPARAM(&sel)); -- cgit v1.2.3