diff --git a/kitty/data-types.h b/kitty/data-types.h index 41b831d50..d3a3d055c 100644 --- a/kitty/data-types.h +++ b/kitty/data-types.h @@ -319,6 +319,7 @@ void play_canberra_sound(const char *which_sound, const char *event_id); #endif SPRITE_MAP_HANDLE alloc_sprite_map(unsigned int, unsigned int); SPRITE_MAP_HANDLE free_sprite_map(SPRITE_MAP_HANDLE); +const char* get_hyperlink_for_id(const HYPERLINK_POOL_HANDLE, hyperlink_id_type id, bool only_url); static inline void safe_close(int fd, const char* file UNUSED, const int line UNUSED) { #if 0 diff --git a/kitty/hyperlink.c b/kitty/hyperlink.c index 88d2432d4..c46989816 100644 --- a/kitty/hyperlink.c +++ b/kitty/hyperlink.c @@ -137,11 +137,11 @@ get_id_for_hyperlink(Screen *screen, const char *id, const char *url) { } const char* -get_hyperlink_for_id(Screen *screen, hyperlink_id_type id) { - HyperLinkPool *pool = (HyperLinkPool*)screen->hyperlink_pool; +get_hyperlink_for_id(const HYPERLINK_POOL_HANDLE handle, hyperlink_id_type id, bool only_url) { + const HyperLinkPool *pool = (HyperLinkPool*)handle; HyperLinkEntry *s, *tmp; HASH_ITER(hh, pool->hyperlinks, s, tmp) { - if (s->id == id) return strstr(s->key, ":") + 1; + if (s->id == id) return only_url ? strstr(s->key, ":") + 1 : s->key; } return NULL; } diff --git a/kitty/hyperlink.h b/kitty/hyperlink.h index 5f96e29a7..67e22381c 100644 --- a/kitty/hyperlink.h +++ b/kitty/hyperlink.h @@ -15,4 +15,3 @@ hyperlink_id_type get_id_for_hyperlink(Screen*, const char*, const char*); hyperlink_id_type remap_hyperlink_ids(Screen *self, hyperlink_id_type *map); PyObject* screen_hyperlinks_as_list(Screen *screen); void screen_garbage_collect_hyperlink_pool(Screen *screen); -const char* get_hyperlink_for_id(Screen *screen, hyperlink_id_type id); diff --git a/kitty/screen.c b/kitty/screen.c index c578bc9f7..767702f9b 100644 --- a/kitty/screen.c +++ b/kitty/screen.c @@ -1956,7 +1956,7 @@ screen_open_url(Screen *self) { if (!self->url_ranges.count) return false; hyperlink_id_type hid = hyperlink_id_for_range(self, self->url_ranges.items); if (hid) { - const char *url = get_hyperlink_for_id(self, hid); + const char *url = get_hyperlink_for_id(self->hyperlink_pool, hid, true); if (url) { CALLBACK("open_url", "sH", url, hid); return true; @@ -2014,7 +2014,7 @@ static PyObject* hyperlink_for_id(Screen *self, PyObject *val) { unsigned long id = PyLong_AsUnsignedLong(val); if (id > HYPERLINK_MAX_NUMBER) { PyErr_SetString(PyExc_IndexError, "Out of bounds"); return NULL; } - return Py_BuildValue("s", get_hyperlink_for_id(self, id)); + return Py_BuildValue("s", get_hyperlink_for_id(self->hyperlink_pool, id, true)); } static PyObject* @@ -2768,7 +2768,7 @@ hyperlink_at(Screen *self, PyObject *args) { if (!self->url_ranges.count) Py_RETURN_NONE; hyperlink_id_type hid = hyperlink_id_for_range(self, self->url_ranges.items); if (!hid) Py_RETURN_NONE; - const char *url = get_hyperlink_for_id(self, hid); + const char *url = get_hyperlink_for_id(self->hyperlink_pool, hid, true); return Py_BuildValue("s", url); }