aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDaniel Eklöf <daniel@ekloef.se>2021-02-14 12:36:07 +0000
committerDaniel Eklöf <daniel@ekloef.se>2021-02-21 19:15:31 +0000
commitcf651d361f382bb572ff0ee60807a17058d4b365 (patch)
treefabe08f9ee608be07b46ca53f6afd3c7473ce722
parentosc-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.c25
1 files changed, 24 insertions, 1 deletions
diff --git a/url-mode.c b/url-mode.c
index 0733a457..7568b922 100644
--- a/url-mode.c
+++ b/url-mode.c
@@ -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);