From a8d1c73fec7d6cf6c790d3c891c5de61a9e93eb4 Mon Sep 17 00:00:00 2001 From: Kovid Goyal Date: Fri, 4 Jun 2021 14:35:22 +0530 Subject: [PATCH] API to get text for currently marked URL --- kitty/screen.c | 18 +++++++++++++++--- 1 file changed, 15 insertions(+), 3 deletions(-) diff --git a/kitty/screen.c b/kitty/screen.c index a8adb50e1..a00c65289 100644 --- a/kitty/screen.c +++ b/kitty/screen.c @@ -2434,10 +2434,10 @@ copy_colors_from(Screen *self, Screen *other) { } static PyObject* -text_for_selection(Screen *self, PyObject *a UNUSED) { +text_for_selections(Screen *self, Selections *selections) { PyObject *lines = NULL; - for (size_t i = 0; i < self->selections.count; i++) { - PyObject *temp = text_for_range(self, self->selections.items + i, true); + for (size_t i = 0; i < selections->count; i++) { + PyObject *temp = text_for_range(self, selections->items + i, true); if (temp) { if (lines) { lines = extend_tuple(lines, temp); @@ -2450,6 +2450,17 @@ text_for_selection(Screen *self, PyObject *a UNUSED) { return lines; } +static PyObject* +text_for_selection(Screen *self, PyObject *a UNUSED) { + return text_for_selections(self, &self->selections); +} + +static PyObject* +text_for_marked_url(Screen *self, PyObject *a UNUSED) { + return text_for_selections(self, &self->url_ranges); +} + + bool screen_selection_range_for_line(Screen *self, index_type y, index_type *start, index_type *end) { if (y >= self->lines) { return false; } @@ -2991,6 +3002,7 @@ static PyMethodDef methods[] = { MND(rescale_images, METH_NOARGS) MND(current_key_encoding_flags, METH_NOARGS) MND(text_for_selection, METH_NOARGS) + MND(text_for_marked_url, METH_NOARGS) MND(is_rectangle_select, METH_NOARGS) MND(scroll, METH_VARARGS) MND(send_escape_code_to_child, METH_VARARGS)