summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorJaakko Keränen <jaakko.keranen@iki.fi>2020-11-21 13:19:17 +0200
committerJaakko Keränen <jaakko.keranen@iki.fi>2020-11-21 13:19:17 +0200
commit6d24d800df86e11c5686d50437932a711af82915 (patch)
treee011f269b0111043b9b02d4477b790ce19380bd7 /src
parentd30daab57241b8ec9e72e24b2f600923d6a231c4 (diff)
DocumentWidget: Marking link icons as search matches
Diffstat (limited to 'src')
-rw-r--r--src/gmdocument.c10
-rw-r--r--src/gmdocument.h1
-rw-r--r--src/ui/documentwidget.c16
3 files changed, 24 insertions, 3 deletions
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)
38 38
39struct Impl_GmLink { 39struct Impl_GmLink {
40 iString url; 40 iString url;
41 iRangecc urlRange; /* URL in the source */
41 iTime when; 42 iTime when;
42 int flags; 43 int flags;
43}; 44};
44 45
45void init_GmLink(iGmLink *d) { 46void init_GmLink(iGmLink *d) {
46 init_String(&d->url); 47 init_String(&d->url);
48 d->urlRange = iNullRange;
47 iZap(d->when); 49 iZap(d->when);
48 d->flags = 0; 50 d->flags = 0;
49} 51}
@@ -161,7 +163,8 @@ static iRangecc addLink_GmDocument_(iGmDocument *d, iRangecc line, iGmLinkId *li
161 init_RegExpMatch(&m); 163 init_RegExpMatch(&m);
162 if (matchRange_RegExp(pattern_, line, &m)) { 164 if (matchRange_RegExp(pattern_, line, &m)) {
163 iGmLink *link = new_GmLink(); 165 iGmLink *link = new_GmLink();
164 setRange_String(&link->url, capturedRange_RegExpMatch(&m, 1)); 166 link->urlRange = capturedRange_RegExpMatch(&m, 1);
167 setRange_String(&link->url, link->urlRange);
165 set_String(&link->url, absoluteUrl_String(&d->url, &link->url)); 168 set_String(&link->url, absoluteUrl_String(&d->url, &link->url));
166 /* Check the URL. */ { 169 /* Check the URL. */ {
167 iUrl parts; 170 iUrl parts;
@@ -1296,6 +1299,11 @@ const iString *linkUrl_GmDocument(const iGmDocument *d, iGmLinkId linkId) {
1296 return link ? &link->url : NULL; 1299 return link ? &link->url : NULL;
1297} 1300}
1298 1301
1302iRangecc linkUrlRange_GmDocument(const iGmDocument *d, iGmLinkId linkId) {
1303 const iGmLink *link = link_GmDocument_(d, linkId);
1304 return link->urlRange;
1305}
1306
1299int linkFlags_GmDocument(const iGmDocument *d, iGmLinkId linkId) { 1307int linkFlags_GmDocument(const iGmDocument *d, iGmLinkId linkId) {
1300 const iGmLink *link = link_GmDocument_(d, linkId); 1308 const iGmLink *link = link_GmDocument_(d, linkId);
1301 return link ? link->flags : 0; 1309 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);
144const char * findLoc_GmDocument (const iGmDocument *, iInt2 pos); 144const char * findLoc_GmDocument (const iGmDocument *, iInt2 pos);
145const iGmRun * findRunAtLoc_GmDocument (const iGmDocument *, const char *loc); 145const iGmRun * findRunAtLoc_GmDocument (const iGmDocument *, const char *loc);
146const iString * linkUrl_GmDocument (const iGmDocument *, iGmLinkId linkId); 146const iString * linkUrl_GmDocument (const iGmDocument *, iGmLinkId linkId);
147iRangecc linkUrlRange_GmDocument (const iGmDocument *, iGmLinkId linkId);
147iMediaId linkImage_GmDocument (const iGmDocument *, iGmLinkId linkId); 148iMediaId linkImage_GmDocument (const iGmDocument *, iGmLinkId linkId);
148iMediaId linkAudio_GmDocument (const iGmDocument *, iGmLinkId linkId); 149iMediaId linkAudio_GmDocument (const iGmDocument *, iGmLinkId linkId);
149int linkFlags_GmDocument (const iGmDocument *, iGmLinkId linkId); 150int 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
2274 else { 2274 else {
2275 *isInside = iTrue; /* at least until the next run */ 2275 *isInside = iTrue; /* at least until the next run */
2276 } 2276 }
2277 if (w > width_Rect(run->visBounds) - x) { 2277 if (w > width_Rect(run->bounds) - x) {
2278 w = width_Rect(run->visBounds) - x; 2278 w = width_Rect(run->bounds) - x;
2279 } 2279 }
2280 const iInt2 visPos = 2280 const iInt2 visPos =
2281 add_I2(run->bounds.pos, addY_I2(d->viewPos, -value_Anim(&d->widget->scrollY))); 2281 add_I2(run->bounds.pos, addY_I2(d->viewPos, -value_Anim(&d->widget->scrollY)));
2282 fillRect_Paint(&d->paint, (iRect){ addX_I2(visPos, x), 2282 fillRect_Paint(&d->paint, (iRect){ addX_I2(visPos, x),
2283 init_I2(w, height_Rect(run->bounds)) }, color); 2283 init_I2(w, height_Rect(run->bounds)) }, color);
2284 } 2284 }
2285 /* Link URLs are not part of the visible document, so they are ignored above. Handle
2286 these ranges as a special case. */
2287 if (run->linkId && run->flags & decoration_GmRunFlag) {
2288 const iRangecc url = linkUrlRange_GmDocument(d->widget->doc, run->linkId);
2289 if (contains_Range(&url, mark.start) &&
2290 (contains_Range(&url, mark.end) || url.end == mark.end)) {
2291 fillRect_Paint(
2292 &d->paint,
2293 moved_Rect(run->visBounds, addY_I2(d->viewPos, -value_Anim(&d->widget->scrollY))),
2294 color);
2295 }
2296 }
2285} 2297}
2286 2298
2287static void drawMark_DrawContext_(void *context, const iGmRun *run) { 2299static void drawMark_DrawContext_(void *context, const iGmRun *run) {