diff options
| author | Daniel Eklöf <daniel@ekloef.se> | 2021-02-14 12:36:07 +0000 |
|---|---|---|
| committer | Daniel Eklöf <daniel@ekloef.se> | 2021-02-21 19:15:31 +0000 |
| commit | cf651d361f382bb572ff0ee60807a17058d4b365 (patch) | |
| tree | fabe08f9ee608be07b46ca53f6afd3c7473ce722 | |
| parent | osc-8: fix thinko: can’t use the ID parameters *address* as actual ID (diff) | |
url-mode: remove duplicate URLs
Remove URLs with the same start and end coordinates. Such duplicate
URLs can be created by emitting an OSC-8 URL with matching grid
content:
\E]8;;http://foo\E\\http://foo\E]8;;\E\\
| -rw-r--r-- | url-mode.c | 25 |
1 files changed, 24 insertions, 1 deletions
@@ -396,12 +396,35 @@ osc8_uris(const struct terminal *term, enum url_action action, url_list_t *urls) } } +static void +remove_duplicates(url_list_t *urls) +{ + tll_foreach(*urls, outer) { + tll_foreach(*urls, inner) { + if (outer == inner) + continue; + + if (outer->item.start.row == inner->item.start.row && + outer->item.start.col == inner->item.start.col && + outer->item.end.row == inner->item.end.row && + outer->item.end.col == inner->item.end.col) + { + free(inner->item.url); + free(inner->item.text); + free(inner->item.key); + tll_remove(*urls, inner); + } + } + } +} + void urls_collect(const struct terminal *term, enum url_action action, url_list_t *urls) { xassert(tll_length(term->urls) == 0); - auto_detected(term, action, urls); osc8_uris(term, action, urls); + auto_detected(term, action, urls); + remove_duplicates(urls); } static void url_destroy(struct url *url); |
