From bcb739fcd2a0ccbb8fe532d1d74b5d21f6a3fdcd Mon Sep 17 00:00:00 2001 From: Kovid Goyal Date: Tue, 11 May 2021 14:20:12 +0530 Subject: [PATCH] Allow clicking URLs to open them without needing to also hold ctrl+shift --- docs/changelog.rst | 3 +++ docs/index.rst | 3 +-- kitty/config_data.py | 6 +++++- kitty/fast_data_types.pyi | 3 +++ kitty/screen.c | 2 ++ kitty/window.py | 4 ++++ 6 files changed, 18 insertions(+), 3 deletions(-) diff --git a/docs/changelog.rst b/docs/changelog.rst index 4064fa45e..e6fac764b 100644 --- a/docs/changelog.rst +++ b/docs/changelog.rst @@ -7,6 +7,9 @@ To update |kitty|, :doc:`follow the instructions `. 0.21.0 [future] ---------------------- +- Allow clicking URLs to open them without needing to also hold + :kbd:`ctrl+shift` + - Allow remapping all mouse button press/release events to perform arbitrary actions. :ref:`See details `. diff --git a/docs/index.rst b/docs/index.rst index 508b26851..f4d1c110a 100644 --- a/docs/index.rst +++ b/docs/index.rst @@ -258,8 +258,7 @@ For example: Mouse features ------------------- -* You can hold down :kbd:`ctrl+shift` and click on a URL to open it in a - browser. +* You can click on a URL to open it in a browser. * You can double click to select a word and then drag to select more words. * You can triple click to select a line and then drag to select more lines. * You can right click to extend a previous selection. diff --git a/kitty/config_data.py b/kitty/config_data.py index 34699cbbe..388dd8039 100644 --- a/kitty/config_data.py +++ b/kitty/config_data.py @@ -665,7 +665,11 @@ Valid values are: :code:`arrow`, :code:`beam` and :code:`hand` g('mouse.mousemap') # {{{ -m('click_url', 'ctrl+shift+left', 'release', 'grabbed,ungrabbed', 'mouse_click_url', _('Click the link under the mouse cursor')) +m('click_url_or_select', 'left', 'click', 'ungrabbed', 'mouse_click_url_or_select', _('Click the link under the mouse cursor when no selection is created')) +m('click_url_or_select_grabbed', 'shift+left', 'click', 'grabbed,ungrabbed', 'mouse_click_url_or_select', _( + 'Click the link under the mouse cursor when no selection is created even if grabbed')) +m('click_url', 'ctrl+shift+left', 'release', 'grabbed,ungrabbed', 'mouse_click_url', + _('Click the link under the mouse cursor'), _('Variant with :kbd:`ctrl+shift` is present only for legacy compatibility.')) for grabbed in (False, True): modes = 'ungrabbed' + (',grabbed' if grabbed else '') diff --git a/kitty/fast_data_types.pyi b/kitty/fast_data_types.pyi index 537a48688..07ccdad5f 100644 --- a/kitty/fast_data_types.pyi +++ b/kitty/fast_data_types.pyi @@ -977,6 +977,9 @@ class Screen: def reset_callbacks(self) -> None: pass + def has_selection(self) -> bool: + pass + def text_for_selection(self) -> Tuple[str, ...]: pass diff --git a/kitty/screen.c b/kitty/screen.c index 87c15ae6d..536546aab 100644 --- a/kitty/screen.c +++ b/kitty/screen.c @@ -2113,6 +2113,7 @@ deactivate_overlay_line(Screen *self) { #define WRAP2B(name) static PyObject* name(Screen *self, PyObject *args) { unsigned int a, b; int p; if(!PyArg_ParseTuple(args, "IIp", &a, &b, &p)) return NULL; screen_##name(self, a, b, (bool)p); Py_RETURN_NONE; } WRAP0(garbage_collect_hyperlink_pool) +WRAP0x(has_selection) static PyObject* hyperlinks_as_list(Screen *self, PyObject *args UNUSED) { @@ -2952,6 +2953,7 @@ static PyMethodDef methods[] = { MND(cursor_down1, METH_VARARGS) MND(cursor_forward, METH_VARARGS) {"index", (PyCFunction)xxx_index, METH_VARARGS, ""}, + {"has_selection", (PyCFunction)xxx_has_selection, METH_VARARGS, ""}, MND(set_pending_timeout, METH_O) MND(as_text, METH_VARARGS) MND(as_text_non_visual, METH_VARARGS) diff --git a/kitty/window.py b/kitty/window.py index 3bac9fa39..af8389c0f 100644 --- a/kitty/window.py +++ b/kitty/window.py @@ -801,6 +801,10 @@ class Window: def mouse_click_url(self) -> None: click_mouse_url(self.os_window_id, self.tab_id, self.id) + def mouse_click_url_or_select(self) -> None: + if not self.screen.has_selection(): + self.mouse_click_url() + def mouse_selection(self, code: int) -> None: mouse_selection(self.os_window_id, self.tab_id, self.id, code, self.current_mouse_event_button)