From da62f092258e313bbd28745a6e32e6d8117f4aa3 Mon Sep 17 00:00:00 2001 From: Jaakko Keränen Date: Fri, 12 Mar 2021 21:24:54 +0200 Subject: DocumentWidget: Bookmarking a wrapped link Only the clicked part of the label text was used for the bookmark. --- src/gmdocument.c | 11 +++++++++++ 1 file changed, 11 insertions(+) (limited to 'src/gmdocument.c') diff --git a/src/gmdocument.c b/src/gmdocument.c index f8e5b8ad..bade99ce 100644 --- a/src/gmdocument.c +++ b/src/gmdocument.c @@ -47,6 +47,7 @@ iDeclareType(GmLink) struct Impl_GmLink { iString url; iRangecc urlRange; /* URL in the source */ + iRangecc labelRange; /* label in the source */ iRangecc labelIcon; /* special icon defined in the label text */ iTime when; int flags; @@ -55,6 +56,7 @@ struct Impl_GmLink { void init_GmLink(iGmLink *d) { init_String(&d->url); d->urlRange = iNullRange; + d->labelRange = iNullRange; iZap(d->when); d->flags = 0; } @@ -235,6 +237,7 @@ static iRangecc addLink_GmDocument_(iGmDocument *d, iRangecc line, iGmLinkId *li *linkId = size_PtrArray(&d->links); /* index + 1 */ iRangecc desc = capturedRange_RegExpMatch(&m, 2); trim_Rangecc(&desc); + link->labelRange = desc; link->labelIcon = iNullRange; if (!isEmpty_Range(&desc)) { line = desc; /* Just show the description. */ @@ -1522,6 +1525,14 @@ iRangecc linkUrlRange_GmDocument(const iGmDocument *d, iGmLinkId linkId) { return link->urlRange; } +iRangecc linkLabel_GmDocument(const iGmDocument *d, iGmLinkId linkId) { + const iGmLink *link = link_GmDocument_(d, linkId); + if (isEmpty_Range(&link->labelRange)) { + return link->urlRange; + } + return link->labelRange; +} + int linkFlags_GmDocument(const iGmDocument *d, iGmLinkId linkId) { const iGmLink *link = link_GmDocument_(d, linkId); return link ? link->flags : 0; -- cgit v1.2.3