summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGeorge Hazan <george.hazan@gmail.com>2023-08-18 19:11:47 +0300
committerGeorge Hazan <george.hazan@gmail.com>2023-08-18 19:11:47 +0300
commit1a9df16b008c77fc8200a7ed746b348e320627b4 (patch)
tree779e7a6a38c7835c10c13d8db69785690dc9f04b
parent28abbea4fcb659887afe752ce81b4f41fda2374d (diff)
NewStory: correct URL length calculation
-rw-r--r--plugins/NewStory/src/history_array.cpp14
1 files changed, 8 insertions, 6 deletions
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));