From cf651d361f382bb572ff0ee60807a17058d4b365 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Ekl=C3=B6f?= Date: Sun, 14 Feb 2021 13:36:07 +0100 Subject: [PATCH] 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\\ --- url-mode.c | 25 ++++++++++++++++++++++++- 1 file changed, 24 insertions(+), 1 deletion(-) 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);