From 6d24d800df86e11c5686d50437932a711af82915 Mon Sep 17 00:00:00 2001 From: Jaakko Keränen Date: Sat, 21 Nov 2020 13:19:17 +0200 Subject: DocumentWidget: Marking link icons as search matches --- res/about/version.gmi | 3 ++- src/gmdocument.c | 10 +++++++++- src/gmdocument.h | 1 + src/ui/documentwidget.c | 16 ++++++++++++++-- 4 files changed, 26 insertions(+), 4 deletions(-) diff --git a/res/about/version.gmi b/res/about/version.gmi index f3d40e76..1b8e502a 100644 --- a/res/about/version.gmi +++ b/res/about/version.gmi @@ -7,11 +7,12 @@ # Release notes ## 0.10 -* Added option to load inline images when pressing Space or ↓. If an image link is visible, the image will be loaded instead of scrolling. This option is disabled by default. +* Added option to load inline images when pressing Space or ↓ for a more focused reading experience — just keep tapping on a single key to proceed. If an image link is visible, it will be loaded instead of scrolling. This option is disabled by default. * Added an option to use a proxy server for Gemini requests. * Added a keybinding to activate keyboard link navigation mode (default is "F"). * Clearing and resetting keybindings via a context menu. * Added a Window tab in the Preferences dialog; moved some of the settings around for better organization. +* Improved page search visualization: if the match is inside a link URL, the link icon is now highlighted. Previously these matches were not visualized in any way. * Improvements to URI parsing with regard to RFC 3986. Cases that are handled better are double slashes, query-only relative URIs, relative URIs that begin with a tilde, IPv6 literals, username in the authority. * Replaced EB Garamond with Tinos for improved readability. * Replaced Kosugi Maru with Noto Sans CJK JP for better glyph coverage. diff --git a/src/gmdocument.c b/src/gmdocument.c index 62a0ba55..80ddfc9d 100644 --- a/src/gmdocument.c +++ b/src/gmdocument.c @@ -38,12 +38,14 @@ iDeclareType(GmLink) struct Impl_GmLink { iString url; + iRangecc urlRange; /* URL in the source */ iTime when; int flags; }; void init_GmLink(iGmLink *d) { init_String(&d->url); + d->urlRange = iNullRange; iZap(d->when); d->flags = 0; } @@ -161,7 +163,8 @@ static iRangecc addLink_GmDocument_(iGmDocument *d, iRangecc line, iGmLinkId *li init_RegExpMatch(&m); if (matchRange_RegExp(pattern_, line, &m)) { iGmLink *link = new_GmLink(); - setRange_String(&link->url, capturedRange_RegExpMatch(&m, 1)); + link->urlRange = capturedRange_RegExpMatch(&m, 1); + setRange_String(&link->url, link->urlRange); set_String(&link->url, absoluteUrl_String(&d->url, &link->url)); /* Check the URL. */ { iUrl parts; @@ -1296,6 +1299,11 @@ const iString *linkUrl_GmDocument(const iGmDocument *d, iGmLinkId linkId) { return link ? &link->url : NULL; } +iRangecc linkUrlRange_GmDocument(const iGmDocument *d, iGmLinkId linkId) { + const iGmLink *link = link_GmDocument_(d, linkId); + return link->urlRange; +} + int linkFlags_GmDocument(const iGmDocument *d, iGmLinkId linkId) { const iGmLink *link = link_GmDocument_(d, linkId); return link ? link->flags : 0; diff --git a/src/gmdocument.h b/src/gmdocument.h index 84af3c98..5234f890 100644 --- a/src/gmdocument.h +++ b/src/gmdocument.h @@ -144,6 +144,7 @@ const iGmRun * findRun_GmDocument (const iGmDocument *, iInt2 pos); const char * findLoc_GmDocument (const iGmDocument *, iInt2 pos); const iGmRun * findRunAtLoc_GmDocument (const iGmDocument *, const char *loc); const iString * linkUrl_GmDocument (const iGmDocument *, iGmLinkId linkId); +iRangecc linkUrlRange_GmDocument (const iGmDocument *, iGmLinkId linkId); iMediaId linkImage_GmDocument (const iGmDocument *, iGmLinkId linkId); iMediaId linkAudio_GmDocument (const iGmDocument *, iGmLinkId linkId); int linkFlags_GmDocument (const iGmDocument *, iGmLinkId linkId); diff --git a/src/ui/documentwidget.c b/src/ui/documentwidget.c index c3c0f527..b1c166aa 100644 --- a/src/ui/documentwidget.c +++ b/src/ui/documentwidget.c @@ -2274,14 +2274,26 @@ static void fillRange_DrawContext_(iDrawContext *d, const iGmRun *run, enum iCol else { *isInside = iTrue; /* at least until the next run */ } - if (w > width_Rect(run->visBounds) - x) { - w = width_Rect(run->visBounds) - x; + if (w > width_Rect(run->bounds) - x) { + w = width_Rect(run->bounds) - x; } const iInt2 visPos = add_I2(run->bounds.pos, addY_I2(d->viewPos, -value_Anim(&d->widget->scrollY))); fillRect_Paint(&d->paint, (iRect){ addX_I2(visPos, x), init_I2(w, height_Rect(run->bounds)) }, color); } + /* Link URLs are not part of the visible document, so they are ignored above. Handle + these ranges as a special case. */ + if (run->linkId && run->flags & decoration_GmRunFlag) { + const iRangecc url = linkUrlRange_GmDocument(d->widget->doc, run->linkId); + if (contains_Range(&url, mark.start) && + (contains_Range(&url, mark.end) || url.end == mark.end)) { + fillRect_Paint( + &d->paint, + moved_Rect(run->visBounds, addY_I2(d->viewPos, -value_Anim(&d->widget->scrollY))), + color); + } + } } static void drawMark_DrawContext_(void *context, const iGmRun *run) { -- cgit v1.2.3