From cc43c1b7048d2cf1cedb48ca63ecde40e2d0dbf5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Ekl=C3=B6f?= Date: Sun, 14 Feb 2021 13:42:37 +0100 Subject: [PATCH] =?UTF-8?q?urls:=20remove=20free-form=20=E2=80=98text?= =?UTF-8?q?=E2=80=99=20member=20from=20URL=20struct?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- render.c | 14 ++------------ terminal.h | 1 - url-mode.c | 11 +++-------- 3 files changed, 5 insertions(+), 21 deletions(-) diff --git a/render.c b/render.c index 0f23fc4e..c9dfc1fc 100644 --- a/render.c +++ b/render.c @@ -2527,7 +2527,6 @@ render_urls(struct terminal *term) tll_foreach(win->urls, it) { const struct url *url = it->item.url; - const wchar_t *text = url->text; const wchar_t *key = url->key; const size_t entered_key_len = wcslen(term->url_keys); @@ -2563,22 +2562,13 @@ render_urls(struct terminal *term) continue; } - size_t text_len = wcslen(text); - size_t chars = wcslen(key) + (text_len > 0 ? 3 + text_len : 0); + size_t chars = wcslen(key); const size_t max_chars = 50; chars = min(chars, max_chars); wchar_t label[chars + 2]; - if (text_len == 0) - wcscpy(label, key); - else { - int count = swprintf(label, chars + 1, L"%ls - %ls", key, text); - if (count >= max_chars) { - label[max_chars] = L'…'; - label[max_chars + 1] = L'\0'; - } - } + wcscpy(label, key); for (size_t i = 0; i < wcslen(key); i++) label[i] = towupper(label[i]); diff --git a/terminal.h b/terminal.h index 284dafa9..cc37bcac 100644 --- a/terminal.h +++ b/terminal.h @@ -252,7 +252,6 @@ enum url_action { URL_ACTION_COPY, URL_ACTION_LAUNCH }; struct url { uint64_t id; char *url; - wchar_t *text; wchar_t *key; struct coord start; struct coord end; diff --git a/url-mode.c b/url-mode.c index 7568b922..44f9bb19 100644 --- a/url-mode.c +++ b/url-mode.c @@ -16,6 +16,8 @@ #include "util.h" #include "xmalloc.h" +static void url_destroy(struct url *url); + static bool execute_binding(struct seat *seat, struct terminal *term, enum bind_action_url action, uint32_t serial) @@ -346,7 +348,6 @@ auto_detected(const struct terminal *term, enum url_action action, ((struct url){ .id = (uint64_t)rand() << 32 | rand(), .url = url_utf8, - .text = xwcsdup(L""), .start = start, .end = end, .action = action})); @@ -388,7 +389,6 @@ osc8_uris(const struct terminal *term, enum url_action action, url_list_t *urls) ((struct url){ .id = it->item.id, .url = xstrdup(it->item.uri), - .text = xwcsdup(L""), .start = start, .end = end, .action = action})); @@ -409,9 +409,7 @@ remove_duplicates(url_list_t *urls) 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); + url_destroy(&inner->item); tll_remove(*urls, inner); } } @@ -427,8 +425,6 @@ urls_collect(const struct terminal *term, enum url_action action, url_list_t *ur remove_duplicates(urls); } -static void url_destroy(struct url *url); - static int wcscmp_qsort_wrapper(const void *_a, const void *_b) { @@ -595,7 +591,6 @@ static void url_destroy(struct url *url) { free(url->url); - free(url->text); free(url->key); }