summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJaakko Keränen <jaakko.keranen@iki.fi>2021-07-17 15:08:59 +0300
committerJaakko Keränen <jaakko.keranen@iki.fi>2021-07-17 15:08:59 +0300
commit635eabab8b932ca01fc5b391cda20e23e40a6532 (patch)
treed7c447ff34efbdd30e683aebf07a415816112159
parent3528bb86ab14c275c41adc7cfa29a5f5eb167ff2 (diff)
GmDocument: Avoid redundant envelope link icon
IssueID #312
-rw-r--r--src/gmdocument.c25
1 files changed, 15 insertions, 10 deletions
diff --git a/src/gmdocument.c b/src/gmdocument.c
index 7079d6e7..fb5f0667 100644
--- a/src/gmdocument.c
+++ b/src/gmdocument.c
@@ -175,6 +175,16 @@ static void setScheme_GmLink_(iGmLink *d, enum iGmLinkScheme scheme) {
175 d->flags |= scheme; 175 d->flags |= scheme;
176} 176}
177 177
178static iBool isAllowedLinkIcon_Char_(iChar icon) {
179 if (isFitzpatrickType_Char(icon)) {
180 return iFalse;
181 }
182 return isPictograph_Char(icon) || isEmoji_Char(icon) ||
183 /* TODO: Add range(s) of 0x2nnn symbols. */
184 icon == 0x2139 /* info */ || icon == 0x2191 /* up arrow */ ||
185 icon == 0x2022 /* bullet */ || icon == 0x2a2f /* close X */ || icon == 0x2b50;
186}
187
178static iRangecc addLink_GmDocument_(iGmDocument *d, iRangecc line, iGmLinkId *linkId) { 188static iRangecc addLink_GmDocument_(iGmDocument *d, iRangecc line, iGmLinkId *linkId) {
179 /* Returns the human-readable label of the link. */ 189 /* Returns the human-readable label of the link. */
180 static iRegExp *pattern_; 190 static iRegExp *pattern_;
@@ -262,19 +272,14 @@ static iRangecc addLink_GmDocument_(iGmDocument *d, iRangecc line, iGmLinkId *li
262 /* Check for a custom icon. */ 272 /* Check for a custom icon. */
263 enum iGmLinkScheme scheme = scheme_GmLinkFlag(link->flags); 273 enum iGmLinkScheme scheme = scheme_GmLinkFlag(link->flags);
264 if ((scheme == gemini_GmLinkScheme && ~link->flags & remote_GmLinkFlag) || 274 if ((scheme == gemini_GmLinkScheme && ~link->flags & remote_GmLinkFlag) ||
265 scheme == file_GmLinkScheme) { 275 scheme == file_GmLinkScheme ||
276 scheme == mailto_GmLinkScheme) {
266 iChar icon = 0; 277 iChar icon = 0;
267 int len = 0; 278 int len = 0;
268 if ((len = decodeBytes_MultibyteChar(desc.start, desc.end, &icon)) > 0) { 279 if ((len = decodeBytes_MultibyteChar(desc.start, desc.end, &icon)) > 0) {
269 if (desc.start + len < desc.end && 280 if (desc.start + len < desc.end &&
270 (isPictograph_Char(icon) || isEmoji_Char(icon) || 281 ((scheme != mailto_GmLinkScheme && isAllowedLinkIcon_Char_(icon)) ||
271 /* TODO: Add range(s) of 0x2nnn symbols. */ 282 (scheme == mailto_GmLinkScheme && icon == 0x1f4e7 /* envelope */))) {
272 icon == 0x2139 /* info */ ||
273 icon == 0x2191 /* up arrow */ ||
274 icon == 0x2022 /* bullet */ ||
275 icon == 0x2a2f /* close X */ ||
276 icon == 0x2b50) &&
277 !isFitzpatrickType_Char(icon)) {
278 link->flags |= iconFromLabel_GmLinkFlag; 283 link->flags |= iconFromLabel_GmLinkFlag;
279 link->labelIcon = (iRangecc){ desc.start, desc.start + len }; 284 link->labelIcon = (iRangecc){ desc.start, desc.start + len };
280 line.start += len; 285 line.start += len;
@@ -1982,7 +1987,7 @@ enum iColorId linkColor_GmDocument(const iGmDocument *d, iGmLinkId linkId, enum
1982 if (isUnsupported) { 1987 if (isUnsupported) {
1983 return tmBadLink_ColorId; 1988 return tmBadLink_ColorId;
1984 } 1989 }
1985 if (link->flags & iconFromLabel_GmLinkFlag) { 1990 if (scheme != mailto_GmLinkScheme && link->flags & iconFromLabel_GmLinkFlag) {
1986 return link->flags & visited_GmLinkFlag ? tmLinkCustomIconVisited_ColorId 1991 return link->flags & visited_GmLinkFlag ? tmLinkCustomIconVisited_ColorId
1987 : tmLinkIcon_ColorId; 1992 : tmLinkIcon_ColorId;
1988 } 1993 }